Skip to content

Commit

Permalink
Suppress incorrect warning in nargsort for timezone-aware DatetimeInd…
Browse files Browse the repository at this point in the history
…ex (#25629)
  • Loading branch information
jorisvandenbossche authored and jreback committed Mar 11, 2019
1 parent 3dfb6d4 commit de52d0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pandas/core/sorting.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" miscellaneous sorting / groupby utilities """
import warnings

import numpy as np

Expand Down Expand Up @@ -254,7 +255,13 @@ def nargsort(items, kind='quicksort', ascending=True, na_position='last'):
sorted_idx = np.roll(sorted_idx, cnt_null)
return sorted_idx

items = np.asanyarray(items)
with warnings.catch_warnings():
# https://github.com/pandas-dev/pandas/issues/25439
# can be removed once ExtensionArrays are properly handled by nargsort
warnings.filterwarnings(
"ignore", category=FutureWarning,
message="Converting timezone-aware DatetimeArray to")
items = np.asanyarray(items)
idx = np.arange(len(items))
mask = isna(items)
non_nans = items[~mask]
Expand Down
10 changes: 9 additions & 1 deletion pandas/tests/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from pandas.compat import PY2

from pandas import DataFrame, MultiIndex, Series, compat, concat, merge
from pandas import (
DataFrame, MultiIndex, Series, compat, concat, merge, to_datetime)
from pandas.core import common as com
from pandas.core.sorting import (
decons_group_index, get_group_index, is_int64_overflow_possible,
Expand Down Expand Up @@ -183,6 +184,13 @@ def test_nargsort(self):
exp = list(range(5)) + list(range(105, 110)) + list(range(104, 4, -1))
tm.assert_numpy_array_equal(result, np.array(exp), check_dtype=False)

def test_nargsort_datetimearray_warning(self):
# https://github.com/pandas-dev/pandas/issues/25439
# can be removed once the FutureWarning for np.array(DTA) is removed
data = to_datetime([0, 2, 0, 1]).tz_localize('Europe/Brussels')
with tm.assert_produces_warning(None):
nargsort(data)


class TestMerge(object):

Expand Down

0 comments on commit de52d0b

Please sign in to comment.