Skip to content

Commit 0b162f5

Browse files
committed
DOC: cleanup whatsnew entry for na_action='ignore'
1 parent d69eaae commit 0b162f5

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

doc/source/whatsnew/v2.1.0.rst

+45-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,47 @@ enhancement1
2121

2222
.. _whatsnew_210.enhancements.enhancement2:
2323

24-
enhancement2
25-
^^^^^^^^^^^^
24+
``map(func, na_action="ignore")`` now works for all array types
25+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
27+
When given a callable, :meth:`Series.map` applies the callable to all elements of the ``Series``.
28+
Similarly, :meth:`DataFrame.applymap` applies the callable to all elements of the ``DataFrame``,
29+
while :meth:`Index.map` applies the callable to all elements of the ``Index``.
30+
31+
Frequently, it is not desirable to apply the callable to nan-like values of the array and to avoid doing
32+
that, the ``map`` method could be called with ``na_action="ignore"``, e.g. like this: ``ser.map(func, na_action="ignore")``.
33+
However, ``na_action="ignore"`` was not implemented for many ``ExtensionArray`` and ``Index`` types
34+
and whether ``na_action="ignore"`` worked with a specific data type was quite unpredictable.
35+
36+
``na_action="ignore"`` now works for all array types (:issue:`52219`, :issue:`51645`, :issue:`51809`, :issue:`51936`, :issue:`52033`; :issue:`52096`).
37+
38+
*Previous behavior*:
39+
40+
.. code-block:: ipython
41+
42+
In [1]: ser = pd.Series(["a", "b", np.nan], dtype="category")
43+
In [2]: ser.map(str.upper, na_action="ignore")
44+
NotImplementedError
45+
In [3]: df = pd.DataFrame(ser)
46+
In [4]: df.applymap(str.upper, na_action="ignore") # worked for DataFrame
47+
0
48+
0 A
49+
1 B
50+
2 NaN
51+
In [5]: idx = pd.Index(ser)
52+
In [6]: idx.map(str.upper, na_action="ignore")
53+
TypeError: CategoricalIndex.map() got an unexpected keyword argument 'na_action'
54+
55+
*New behavior*:
56+
57+
.. ipython:: python
58+
59+
ser = pd.Series(["a", "b", np.nan], dtype="category")
60+
ser.map(str.upper, na_action="ignore")
61+
df = pd.DataFrame(ser)
62+
df.applymap(str.upper, na_action="ignore")
63+
idx = pd.Index(ser)
64+
idx.map(str.upper, na_action="ignore")
2665
2766
.. _whatsnew_210.enhancements.other:
2867

@@ -34,6 +73,7 @@ Other enhancements
3473
- Implemented ``__pandas_priority__`` to allow custom types to take precedence over :class:`DataFrame`, :class:`Series`, :class:`Index`, or :class:`ExtensionArray` for arithmetic operations, :ref:`see the developer guide <extending.pandas_priority>` (:issue:`48347`)
3574
- :meth:`MultiIndex.sort_values` now supports ``na_position`` (:issue:`51612`)
3675
- :meth:`MultiIndex.sortlevel` and :meth:`Index.sortlevel` gained a new keyword ``na_position`` (:issue:`51612`)
76+
- :meth:`arrays.DatetimeArray.map`, :meth:`arrays.TimedeltaArray.map` and :meth:`arrays.PeriodArray.map` can now take a ``na_action`` argument (:issue:`51644`)
3777
- Improve error message when setting :class:`DataFrame` with wrong number of columns through :meth:`DataFrame.isetitem` (:issue:`51701`)
3878
- Let :meth:`DataFrame.to_feather` accept a non-default :class:`Index` and non-string column names (:issue:`51787`)
3979
- :class:`api.extensions.ExtensionArray` now has a :meth:`~api.extensions.ExtensionArray.map` method (:issue:`51809`)
@@ -42,7 +82,6 @@ Other enhancements
4282
- Improved error message when creating a DataFrame with empty data (0 rows), no index and an incorrect number of columns. (:issue:`52084`)
4383
- :meth:`DataFrame.applymap` now uses the :meth:`~api.extensions.ExtensionArray.map` method of underlying :class:`api.extensions.ExtensionArray` instances (:issue:`52219`)
4484
- :meth:`arrays.SparseArray.map` now supports ``na_action`` (:issue:`52096`).
45-
- :meth:`Categorical.map` and :meth:`CategoricalIndex.map` now have a ``na_action`` parameter (:issue:`44279`)
4685
- Add dtype of categories to ``repr`` information of :class:`CategoricalDtype` (:issue:`52179`)
4786
-
4887

@@ -163,15 +202,15 @@ Categorical
163202
Datetimelike
164203
^^^^^^^^^^^^
165204
- Bug in :meth:`Timestamp.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsDatetime`` (:issue:`51494`)
166-
- :meth:`arrays.DatetimeArray.map` can now take a ``na_action`` argument. :meth:`DatetimeIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
205+
- :meth:`DatetimeIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
167206
- Bug in :meth:`arrays.DatetimeArray.map` and :meth:`DatetimeIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
168207
-
169208

170209
Timedelta
171210
^^^^^^^^^
172211
- Bug in :meth:`Timedelta.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsTimedelta`` (:issue:`51494`)
173212
- Bug in :class:`TimedeltaIndex` division or multiplication leading to ``.freq`` of "0 Days" instead of ``None`` (:issue:`51575`)
174-
- :meth:`arrays.TimedeltaArray.map` can now take a ``na_action`` argument. :meth:`TimedeltaIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
213+
- :meth:`TimedeltaIndex.map` with ``na_action="ignore"`` now works as expected (:issue:`51644`)
175214
- Bug in :meth:`arrays.TimedeltaArray.map` and :meth:`TimedeltaIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
176215
-
177216

@@ -227,7 +266,7 @@ I/O
227266
Period
228267
^^^^^^
229268
- Bug in :class:`PeriodDtype` constructor failing to raise ``TypeError`` when no argument is passed or when ``None`` is passed (:issue:`27388`)
230-
- :meth:`arrays.PeriodArray.map` can now take a ``na_action`` argument. :meth:`PeriodIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
269+
- :meth:`PeriodIndex.map` with ``na_action="ignore"`` now works as expected (:issue:`51644`)
231270
- Bug in :class:`PeriodDtype` constructor raising ``ValueError`` instead of ``TypeError`` when an invalid type is passed (:issue:`51790`)
232271
- Bug in :meth:`arrays.PeriodArray.map` and :meth:`PeriodIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
233272
-

0 commit comments

Comments
 (0)