From 92170c22d92ce3895c6c4482fe4d7fbe5f3c4856 Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Wed, 12 Aug 2020 14:00:52 -0500 Subject: [PATCH] Add try_sort() to eland.utils This function was deprecated and removed in Pandas v1.1 --- eland/plotting/_matplotlib/hist.py | 4 ++-- eland/utils.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/eland/plotting/_matplotlib/hist.py b/eland/plotting/_matplotlib/hist.py index 58ba850..197d9b9 100644 --- a/eland/plotting/_matplotlib/hist.py +++ b/eland/plotting/_matplotlib/hist.py @@ -16,10 +16,10 @@ # under the License. import numpy as np -import pandas.core.common as com from pandas.core.dtypes.generic import ABCIndexClass from pandas.plotting._matplotlib import converter from pandas.plotting._matplotlib.tools import _flatten, _set_ticks_props, _subplots +from eland.utils import try_sort def hist_series( @@ -120,7 +120,7 @@ def hist_frame( ) _axes = _flatten(axes) - for i, col in enumerate(com.try_sort(data.columns)): + for i, col in enumerate(try_sort(data.columns)): ax = _axes[i] ax.hist( ed_df_bins[col][:-1], diff --git a/eland/utils.py b/eland/utils.py index 4530fcb..e643b48 100644 --- a/eland/utils.py +++ b/eland/utils.py @@ -18,7 +18,7 @@ import re import functools import warnings -from typing import Callable, TypeVar, Any, Union, List, cast, Collection +from typing import Callable, TypeVar, Any, Union, List, cast, Collection, Iterable from collections.abc import Collection as ABCCollection import pandas as pd # type: ignore @@ -59,3 +59,13 @@ def to_list(x: Union[Collection[Any], pd.Series]) -> List[Any]: elif isinstance(x, pd.Series): return cast(List[Any], x.to_list()) raise NotImplementedError(f"Could not convert {type(x).__name__} into a list") + + +def try_sort(iterable: Iterable[Item]) -> Iterable[Item]: + # Pulled from pandas.core.common since + # it was deprecated and removed in 1.1 + listed = list(iterable) + try: + return sorted(listed) + except TypeError: + return listed