Skip to content

Commit

Permalink
updates for backwards compatability
Browse files Browse the repository at this point in the history
  • Loading branch information
aschonfeld committed Apr 19, 2023
1 parent f87b1dd commit 6be8866
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
8 changes: 6 additions & 2 deletions dtale/pandas_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
from pkg_resources import parse_version


def check_pandas_version(version_number):
return parse_version(pd.__version__) >= parse_version(version_number)


def has_dropna():
return parse_version(pd.__version__) >= parse_version("1.1.0")
return check_pandas_version("1.1.0")


def groupby(df, index, dropna=True):
Expand All @@ -22,4 +26,4 @@ def groupby_code(index, dropna=True):


def is_pandas2():
return parse_version(pd.__version__) >= parse_version("2.0.0")
return check_pandas_version("2.0.0")
8 changes: 7 additions & 1 deletion dtale/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,13 @@ def describe(data_id):
.sort_values(["count", "value"], ascending=[False, True])
.head(100)
)
uniq_grp["value"] = uniq_grp["value"].astype(uniq_type)
# pandas started supporting string dtypes in 1.1.0
conversion_type = (
"object"
if pandas_util.check_pandas_version("1.1.0") and uniq_type == "string"
else uniq_type
)
uniq_grp["value"] = uniq_grp["value"].astype(conversion_type)
uniq_f, _ = build_formatters(uniq_grp)
return_data["uniques"][uniq_type] = dict(
data=uniq_f.format_dicts(uniq_grp.itertuples()), total=total, top=top
Expand Down
5 changes: 2 additions & 3 deletions tests/dtale/dash/test_extended_aggregation_charts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pandas as pd
import platform
import pytest
from pkg_resources import parse_version

import dtale.global_state as global_state

Expand Down Expand Up @@ -121,8 +121,7 @@ def test_bar_and_popup(unittest):
"title": {"text": "Mean of c"},
},
}
major, minor, revision = [int(i) for i in platform.python_version_tuple()]
if major == 3 and minor > 6:
if parse_version(pd.__version__) >= parse_version("1.3.0"):
del expected["yaxis2"]["tickformat"]
unittest.assertEqual(
resp_data["chart-content"]["children"]["props"]["children"][1]["props"][
Expand Down
5 changes: 2 additions & 3 deletions tests/dtale/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import os
import dtale.global_state as global_state
import pandas as pd
import platform
import pytest
from pandas.tseries.offsets import Day
from pkg_resources import parse_version
from six import PY3

import dtale.pandas_util as pandas_util
Expand Down Expand Up @@ -1233,8 +1233,7 @@ def _df():
response = c.get(
"/dtale/variance/{}".format(c.port), query_string=dict(col="x")
)
major, minor, revision = [int(i) for i in platform.python_version_tuple()]
if major == 3 and minor > 6:
if parse_version(pd.__version__) >= parse_version("1.3.0"):
expected["x"]["check2"]["val1"]["val"] = 0
expected["x"]["check2"]["val2"]["val"] = 1
response_data = json.loads(response.data)
Expand Down

0 comments on commit 6be8866

Please sign in to comment.