Skip to content

Commit ab168e7

Browse files
committed
Update whatsnew and add git PR to tests to denote changes
1 parent 504c2a2 commit ab168e7

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

doc/source/whatsnew/v0.20.0.txt

+100
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ Other enhancements
9191
Backwards incompatible API changes
9292
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9393

94+
95+
Map on Index types now return other Index types
96+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
9498
- ``map`` on an ``Index`` now returns an ``Index``, not an array (:issue:`12766`)
9599

96100
.. ipython:: python
@@ -111,6 +115,102 @@ Backwards incompatible API changes
111115

112116
idx.map(lambda x: x * 2)
113117

118+
- ``map`` on an ``Index`` or ``MultiIndex`` returns the appropriate type depending on output dimensionality
119+
120+
.. ipython:: python
121+
122+
mi = MultiIndex.from_tuples([(1, 2), (2, 4)])
123+
mi
124+
125+
Previous Behavior:
126+
127+
.. code-block:: ipython
128+
129+
In [5]: idx.map(lambda x: (x, x * 2))
130+
Out[5]: array([(1, 2), (2, 4)], dtype=object)
131+
132+
133+
In [6]: mi.map(lambda x: x[0])
134+
Out[6]: array([1, 2])
135+
136+
New Behavior:
137+
138+
.. ipython:: python
139+
140+
idx.map(lambda x: (x, x * 2))
141+
142+
mi.map(lambda x: x[0])
143+
144+
145+
- ``map`` on an ``CategoricalIndex`` now returns a ``CategoricalIndex``, not a Categorical
146+
147+
.. ipython:: python
148+
149+
ci = CategoricalIndex(list('ABABC'), categories=list('CBA'), ordered=True)
150+
ci
151+
152+
Previous Behavior:
153+
154+
.. code-block:: ipython
155+
156+
In [7]: ci.map(lambda x: x.lower())
157+
Out[7]:
158+
[a, b, a, b, c]
159+
Categories (3, object): [c < b < a]
160+
161+
New Behavior:
162+
163+
.. ipython:: python
164+
165+
ci.map(lambda x: x.lower())
166+
167+
- ``map`` on an ``DatetimeIndex`` or ``TimedeltaIndex`` now returns an ``Index`` instance
168+
169+
.. ipython:: python
170+
171+
dtidx = date_range(start='2016-01-01', end='2016-01-02')
172+
dtidx
173+
174+
Previous Behavior:
175+
176+
.. code-block:: ipython
177+
178+
In [8]: dtidx.map(lambda x: x.day)
179+
Out[8]: array([1, 2])
180+
181+
New Behavior:
182+
183+
.. ipython:: python
184+
185+
dtidx.map(lambda x: x.day)
186+
187+
188+
- ``map`` on a Series withe datetime64 values may return int64 dtypes rather than int32
189+
190+
.. ipython:: python
191+
192+
s = Series(date_range('2011-01-02T00:00', '2011-01-02T02:00', freq='H').tz_localize('Asia/Tokyo'))
193+
s
194+
195+
Previous Behavior:
196+
197+
.. code-block:: ipython
198+
199+
In [9]: s.map(lambda x: x.hour)
200+
Out[9]:
201+
0 0
202+
1 1
203+
2 2
204+
dtype: int32
205+
206+
207+
New Behavior:
208+
209+
.. ipython:: python
210+
211+
s.map(lambda x: x.hour)
212+
213+
114214
.. _whatsnew_0200.api:
115215

116216
- ``CParserError`` has been renamed to ``ParserError`` in ``pd.read_csv`` and will be removed in the future (:issue:`12665`)

pandas/tests/series/test_apply.py

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def test_apply_datetimetz(self):
123123
tm.assert_series_equal(result, exp)
124124

125125
# change dtype
126+
# GH 14506 : Returned dtype changed from int32 to int64
126127
result = s.apply(lambda x: x.hour)
127128
exp = pd.Series(list(range(24)) + [0], name='XX', dtype=np.int64)
128129
tm.assert_series_equal(result, exp)
@@ -317,6 +318,7 @@ def test_map_datetimetz(self):
317318
tm.assert_series_equal(result, exp)
318319

319320
# change dtype
321+
# GH 14506 : Returned dtype changed from int32 to int64
320322
result = s.map(lambda x: x.hour)
321323
exp = pd.Series(list(range(24)) + [0], name='XX', dtype=np.int64)
322324
tm.assert_series_equal(result, exp)

0 commit comments

Comments
 (0)