Skip to content
Prev Previous commit
Next Next commit
Fix black issue and the test error
  • Loading branch information
makbigc committed Nov 1, 2019
commit 095e6da6613fce89b39d3b5d095b87f465bbac02
18 changes: 12 additions & 6 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2216,9 +2216,12 @@ def min(self, skipna=None, **kwargs):
if skipna:
pointer = self._codes[good].min(**kwargs)
else:
msg = ("The default value of skipna will be changed to "
"True in the future version.")
warn(msg, FutureWarning, stacklevel=2)
if skipna is None:
msg = (
"The default value of skipna will be changed to "
"True in the future version."
)
warn(msg, FutureWarning, stacklevel=2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this if skipna is None block with the warning I think?

return np.nan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not correct for i8 types, which should be pd.NaT. how to fix this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could check the categories.dtype.na_value if it exists. But since this is the current behaviour, it's not critical to fix in this PR I think.

else:
pointer = self._codes.min(**kwargs)
Expand Down Expand Up @@ -2246,9 +2249,12 @@ def max(self, skipna=None, **kwargs):
if skipna:
pointer = self._codes[good].max(**kwargs)
else:
msg = ("The default value of skipna will be changed to "
"True in the future version.")
warn(msg, FutureWarning, stacklevel=2)
if skipna is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

msg = (
"The default value of skipna will be changed to "
"True in the future version."
)
warn(msg, FutureWarning, stacklevel=2)
return np.nan
else:
pointer = self._codes.max(**kwargs)
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/arrays/categorical/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def test_deprecate_numeric_only_min_max(self, method):
cat = Categorical(
[np.nan, 1, 2, np.nan], categories=[5, 4, 3, 2, 1], ordered=True
)
with tm.assert_produces_warning(expected_warning=FutureWarning,
check_stacklevel=False):
with tm.assert_produces_warning(
expected_warning=FutureWarning, check_stacklevel=False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work without check_stacklevel=False ?

):
getattr(cat, method)(numeric_only=True)

@pytest.mark.parametrize(
Expand Down