From a6e43a43f2cb1b4b7d46b262be2efb825d033eb8 Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Mon, 13 May 2019 12:17:03 -0500 Subject: [PATCH] COMPAT: Compat with numpy dev argsort (radix sort added) (#26373) * Compat with numpy dev https://github.com/numpy/numpy/commit/12fb1015511ac3804d0785bb0d1fe539385548ad adds radix sort to np.argsort. For versions of NumPy with this change (>=1.17), we need to adjust our validator. Closes https://github.com/pandas-dev/pandas/issues/26361 * isort --- pandas/compat/numpy/function.py | 9 ++++++++- pandas/tests/groupby/test_groupby.py | 3 +-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pandas/compat/numpy/function.py b/pandas/compat/numpy/function.py index ef009f8ff4d77..572dd7272986b 100644 --- a/pandas/compat/numpy/function.py +++ b/pandas/compat/numpy/function.py @@ -18,9 +18,10 @@ easier to adjust to future upstream changes in the analogous numpy signatures. """ from collections import OrderedDict +from distutils.version import LooseVersion from typing import Any, Dict, Optional, Union -from numpy import ndarray +from numpy import __version__ as _np_version, ndarray from pandas._libs.lib import is_bool, is_integer from pandas.errors import UnsupportedFunctionCall @@ -107,6 +108,12 @@ def validate_argmax_with_skipna(skipna, args, kwargs): ARGSORT_DEFAULTS['axis'] = -1 ARGSORT_DEFAULTS['kind'] = 'quicksort' ARGSORT_DEFAULTS['order'] = None + +if LooseVersion(_np_version) >= LooseVersion("1.17.0"): + # GH-26361. NumPy added radix sort and changed default to None. + ARGSORT_DEFAULTS['kind'] = None + + validate_argsort = CompatValidator(ARGSORT_DEFAULTS, fname='argsort', max_fname_arg_count=0, method='both') diff --git a/pandas/tests/groupby/test_groupby.py b/pandas/tests/groupby/test_groupby.py index 354242995d3c3..39d3ffdb286ab 100644 --- a/pandas/tests/groupby/test_groupby.py +++ b/pandas/tests/groupby/test_groupby.py @@ -10,8 +10,7 @@ import pandas as pd from pandas import ( - DataFrame, Index, MultiIndex, Series, Timestamp, date_range, - read_csv) + DataFrame, Index, MultiIndex, Series, Timestamp, date_range, read_csv) import pandas.core.common as com import pandas.util.testing as tm from pandas.util.testing import (