@@ -91,6 +91,10 @@ Other enhancements
91
91
Backwards incompatible API changes
92
92
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93
93
94
+
95
+ Map on Index types now return other Index types
96
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97
+
94
98
- ``map`` on an ``Index`` now returns an ``Index``, not an array (:issue:`12766`)
95
99
96
100
.. ipython:: python
@@ -111,6 +115,102 @@ Backwards incompatible API changes
111
115
112
116
idx.map(lambda x: x * 2)
113
117
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
+
114
214
.. _whatsnew_0200.api:
115
215
116
216
- ``CParserError`` has been renamed to ``ParserError`` in ``pd.read_csv`` and will be removed in the future (:issue:`12665`)
0 commit comments