You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When given a callable, :meth:`Series.map` applies the callable to all elements of the :class:`Series`.
28
+
Similarly, :meth:`DataFrame.applymap` applies the callable to all elements of the :class:`DataFrame`,
29
+
while :meth:`Index.map` applies the callable to all elements of the :class:`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"``, i.e. ``ser.map(func, na_action="ignore")``.
33
+
However, ``na_action="ignore"`` was not implemented for many ``ExtensionArray`` and ``Index`` types
34
+
and ``na_action="ignore"`` did not work correctly for any ``ExtensionArray`` subclass except the nullable numeric ones (i.e. with dtype :class:`Int64` etc.).
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")
65
+
66
+
Also, note that :meth:`Categorical.map` implicitly has had its ``na_action`` set to ``"ignore"`` by default.
67
+
This has been deprecated and will :meth:`Categorical.map` in the future change the default
68
+
to ``na_action=None``, like for all the other array types.
26
69
27
70
.. _whatsnew_210.enhancements.other:
28
71
@@ -34,6 +77,7 @@ Other enhancements
34
77
- 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`)
35
78
- :meth:`MultiIndex.sort_values` now supports ``na_position`` (:issue:`51612`)
36
79
- :meth:`MultiIndex.sortlevel` and :meth:`Index.sortlevel` gained a new keyword ``na_position`` (:issue:`51612`)
80
+
- :meth:`arrays.DatetimeArray.map`, :meth:`arrays.TimedeltaArray.map` and :meth:`arrays.PeriodArray.map` can now take a ``na_action`` argument (:issue:`51644`)
37
81
- Improve error message when setting :class:`DataFrame` with wrong number of columns through :meth:`DataFrame.isetitem` (:issue:`51701`)
38
82
- Let :meth:`DataFrame.to_feather` accept a non-default :class:`Index` and non-string column names (:issue:`51787`)
39
83
- :class:`api.extensions.ExtensionArray` now has a :meth:`~api.extensions.ExtensionArray.map` method (:issue:`51809`)
@@ -42,7 +86,6 @@ Other enhancements
42
86
- Improved error message when creating a DataFrame with empty data (0 rows), no index and an incorrect number of columns. (:issue:`52084`)
43
87
- :meth:`DataFrame.applymap` now uses the :meth:`~api.extensions.ExtensionArray.map` method of underlying :class:`api.extensions.ExtensionArray` instances (:issue:`52219`)
44
88
- :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`)
46
89
- Add dtype of categories to ``repr`` information of :class:`CategoricalDtype` (:issue:`52179`)
47
90
-
48
91
@@ -110,6 +153,7 @@ Deprecations
110
153
- Deprecated :meth:`DataFrame._data` and :meth:`Series._data`, use public APIs instead (:issue:`33333`)
111
154
- Deprecated :meth:`.Groupby.all` and :meth:`.GroupBy.any` with datetime64 or :class:`PeriodDtype` values, matching the :class:`Series` and :class:`DataFrame` deprecations (:issue:`34479`)
112
155
- Deprecating pinning ``group.name`` to each group in :meth:`SeriesGroupBy.aggregate` aggregations; if your operation requires utilizing the groupby keys, iterate over the groupby object instead (:issue:`41090`)
156
+
- Deprecated the behavior of :func:`concat` with both ``len(keys) != len(objs)``, in a future version this will raise instead of truncating to the shorter of the two sequences (:issue:`43485`)
113
157
- Deprecated the default of ``observed=False`` in :meth:`DataFrame.groupby` and :meth:`Series.groupby`; this will default to ``True`` in a future version (:issue:`43999`)
114
158
- Deprecated explicit support for subclassing :class:`Index` (:issue:`45289`)
115
159
- Deprecated :meth:`DataFrameGroupBy.dtypes`, check ``dtypes`` on the underlying object instead (:issue:`51045`)
@@ -125,10 +169,12 @@ Deprecations
125
169
- Deprecated the 'axis' keyword in :meth:`.GroupBy.idxmax`, :meth:`.GroupBy.idxmin`, :meth:`.GroupBy.fillna`, :meth:`.GroupBy.take`, :meth:`.GroupBy.skew`, :meth:`.GroupBy.rank`, :meth:`.GroupBy.cumprod`, :meth:`.GroupBy.cumsum`, :meth:`.GroupBy.cummax`, :meth:`.GroupBy.cummin`, :meth:`.GroupBy.pct_change`, :meth:`GroupBy.diff`, :meth:`.GroupBy.shift`, and :meth:`DataFrameGroupBy.corrwith`; for ``axis=1`` operate on the underlying :class:`DataFrame` instead (:issue:`50405`, :issue:`51046`)
126
170
- Deprecated passing a dictionary to :meth:`.SeriesGroupBy.agg`; pass a list of aggregations instead (:issue:`50684`)
127
171
- Deprecated logical operations (``|``, ``&``, ``^``) between pandas objects and dtype-less sequences (e.g. ``list``, ``tuple``), wrap a sequence in a :class:`Series` or numpy array before operating instead (:issue:`51521`)
172
+
- Deprecated the methods :meth:`Series.bool` and :meth:`DataFrame.bool` (:issue:`51749`)
128
173
- Deprecated :meth:`DataFrame.swapaxes` and :meth:`Series.swapaxes`, use :meth:`DataFrame.transpose` or :meth:`Series.transpose` instead (:issue:`51946`)
129
174
- Deprecated parameter ``convert_type`` in :meth:`Series.apply` (:issue:`52140`)
- 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`)
214
+
- :meth:`DatetimeIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
167
215
- Bug in :meth:`arrays.DatetimeArray.map` and :meth:`DatetimeIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
168
216
- Bug in :class:`Timestamp` raising an error when passing fold when constructing from positional arguments.
169
217
- Bug in :class:`Timestamp` leading to inconsistent timestamps when passing arguments as positional versus as a keyword.
@@ -173,7 +221,7 @@ Timedelta
173
221
^^^^^^^^^
174
222
- Bug in :meth:`Timedelta.round` with values close to the implementation bounds returning incorrect results instead of raising ``OutOfBoundsTimedelta`` (:issue:`51494`)
175
223
- Bug in :class:`TimedeltaIndex` division or multiplication leading to ``.freq`` of "0 Days" instead of ``None`` (:issue:`51575`)
176
-
- :meth:`arrays.TimedeltaArray.map` can now take a ``na_action`` argument. :meth:`TimedeltaIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
224
+
- :meth:`TimedeltaIndex.map` with ``na_action="ignore"`` now works as expected (:issue:`51644`)
177
225
- Bug in :meth:`arrays.TimedeltaArray.map` and :meth:`TimedeltaIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
178
226
-
179
227
@@ -229,7 +277,7 @@ I/O
229
277
Period
230
278
^^^^^^
231
279
- Bug in :class:`PeriodDtype` constructor failing to raise ``TypeError`` when no argument is passed or when ``None`` is passed (:issue:`27388`)
232
-
- :meth:`arrays.PeriodArray.map` can now take a ``na_action`` argument. :meth:`PeriodIndex.map` with ``na_action="ignore"`` now works as expected. (:issue:`51644`)
280
+
- :meth:`PeriodIndex.map` with ``na_action="ignore"`` now works as expected (:issue:`51644`)
233
281
- Bug in :class:`PeriodDtype` constructor raising ``ValueError`` instead of ``TypeError`` when an invalid type is passed (:issue:`51790`)
234
282
- Bug in :meth:`arrays.PeriodArray.map` and :meth:`PeriodIndex.map`, where the supplied callable operated array-wise instead of element-wise (:issue:`51977`)
235
283
-
@@ -276,6 +324,8 @@ Other
276
324
^^^^^
277
325
- Bug in :func:`assert_almost_equal` now throwing assertion error for two unequal sets (:issue:`51727`)
278
326
- Bug in :meth:`Series.memory_usage` when ``deep=True`` throw an error with Series of objects and the returned value is incorrect, as it does not take into account GC corrections (:issue:`51858`)
327
+
- Bug in :func:`assert_frame_equal` checks category dtypes even when asked not to check index type (:issue:`52126`)
328
+
- Bug in :meth:`Series.map` when giving a callable to an empty series, the returned series had ``object`` dtype. It now keeps the original dtype (:issue:`52384`)
0 commit comments