From 6be8866b6d0a513aa5284bef42852a95f9a7b4c3 Mon Sep 17 00:00:00 2001 From: "Andrew Schonfeld (Boston)" Date: Tue, 18 Apr 2023 15:59:26 -0400 Subject: [PATCH] updates for backwards compatability --- dtale/pandas_util.py | 8 ++++++-- dtale/views.py | 8 +++++++- tests/dtale/dash/test_extended_aggregation_charts.py | 5 ++--- tests/dtale/test_views.py | 5 ++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/dtale/pandas_util.py b/dtale/pandas_util.py index a4451f3f..60bf71c2 100644 --- a/dtale/pandas_util.py +++ b/dtale/pandas_util.py @@ -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): @@ -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") diff --git a/dtale/views.py b/dtale/views.py index 2d621e91..cda050dc 100644 --- a/dtale/views.py +++ b/dtale/views.py @@ -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 diff --git a/tests/dtale/dash/test_extended_aggregation_charts.py b/tests/dtale/dash/test_extended_aggregation_charts.py index 262c65bb..f136af34 100644 --- a/tests/dtale/dash/test_extended_aggregation_charts.py +++ b/tests/dtale/dash/test_extended_aggregation_charts.py @@ -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 @@ -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"][ diff --git a/tests/dtale/test_views.py b/tests/dtale/test_views.py index b4950976..787993d2 100644 --- a/tests/dtale/test_views.py +++ b/tests/dtale/test_views.py @@ -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 @@ -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)