Skip to content

Commit 3a98ede

Browse files
committed
Updates
1 parent aa7266c commit 3a98ede

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

doc/source/whatsnew/v0.23.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ Other API Changes
856856
- Constructing a Series from a list of length 1 no longer broadcasts this list when a longer index is specified (:issue:`19714`, :issue:`20391`).
857857
- :func:`DataFrame.to_dict` with ``orient='index'`` no longer casts int columns to float for a DataFrame with only int and float columns (:issue:`18580`)
858858
- A user-defined-function that is passed to :func:`Series.rolling().aggregate() <pandas.core.window.Rolling.aggregate>`, :func:`DataFrame.rolling().aggregate() <pandas.core.window.Rolling.aggregate>`, or its expanding cousins, will now *always* be passed a ``Series``, rather than a ``np.array``; ``.apply()`` only has the ``raw`` keyword, see :ref:`here <whatsnew_0230.enhancements.window_raw>`. This is consistent with the signatures of ``.aggregate()`` across pandas (:issue:`20584`)
859-
- The previous default behavior of negative indices in ``Categorical.take`` is deprecated. In a future version it will change from meaning missing values to meaning positional indicies from the right (:issue:`20664`)
859+
- The previous default behavior of negative indices in ``Categorical.take`` is deprecated. In a future version it will change from meaning missing values to meaning positional indices from the right. The future behavior is consistent with :meth:`Series.take` (:issue:`20664`).
860860

861861
.. _whatsnew_0230.deprecations:
862862

@@ -1025,6 +1025,7 @@ Categorical
10251025
- Bug in ``Categorical.__iter__`` not converting to Python types (:issue:`19909`)
10261026
- Bug in :func:`pandas.factorize` returning the unique codes for the ``uniques``. This now returns a ``Categorical`` with the same dtype as the input (:issue:`19721`)
10271027
- Bug in :func:`pandas.factorize` including an item for missing values in the ``uniques`` return value (:issue:`19721`)
1028+
- Bug in :meth:`Series.take` with categorical data interpreting ``-1`` in `indicies` as missing value markers, rather than the last element of the Series (:issue:`20664`)
10281029

10291030
Datetimelike
10301031
^^^^^^^^^^^^

pandas/core/arrays/categorical.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -1746,9 +1746,33 @@ def fillna(self, value=None, method=None, limit=None):
17461746

17471747
def take_nd(self, indexer, allow_fill=None, fill_value=None):
17481748
"""
1749-
Return the indices
1749+
Take elements from the Categorical.
17501750
1751-
For internal compatibility with numpy arrays.
1751+
Parameters
1752+
----------
1753+
indexer : sequence of integers
1754+
allow_fill : bool, default None.
1755+
How to handle negative values in `indexer`.
1756+
1757+
* False: negative values in `indices` indicate positional indices
1758+
from the right. This is similar to
1759+
:func:`numpy.take`.
1760+
1761+
* True: negative values in `indices` indicate missing values
1762+
(the default). These values are set to `fill_value`. Any other
1763+
other negative values raise a ``ValueError``.
1764+
1765+
.. versionchanged:: 0.23.0
1766+
1767+
Deprecated the default value of `allow_fill`. The deprecated
1768+
default is ``True``. In the future, this will change to
1769+
``False``.
1770+
1771+
Returns
1772+
-------
1773+
Categorical
1774+
This Categorical will have the same categories and ordered as
1775+
`self`.
17521776
"""
17531777
indexer = np.asarray(indexer, dtype=np.intp)
17541778
if allow_fill is None:
@@ -1757,8 +1781,8 @@ def take_nd(self, indexer, allow_fill=None, fill_value=None):
17571781
allow_fill = True
17581782

17591783
if fill_value is None or isna(fill_value):
1760-
# For backwards compatability, we have to override
1761-
# any na values for `fill_value`
1784+
# The isna(fill_value) is included for backwards compatability.
1785+
# Categorical overrides any NA value with -1.
17621786
fill_value = -1
17631787

17641788
codes = take(self._codes, indexer, allow_fill=allow_fill,

pandas/tests/extension/category/test_categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_take_non_na_fill_value(self):
111111
def test_take_out_of_bounds_raises(self):
112112
pass
113113

114-
@skip_take
114+
@pytest.mark.skip(reason="GH-20747. Unobserved categories.")
115115
def test_take_series(self):
116116
pass
117117

0 commit comments

Comments
 (0)