@@ -12,7 +12,7 @@ Highlights include:
12
12
13
13
Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations <whatsnew_0200.deprecations>` before updating.
14
14
15
- .. contents:: What's new in v0.19 .0
15
+ .. contents:: What's new in v0.20 .0
16
16
:local:
17
17
:backlinks: none
18
18
@@ -38,6 +38,10 @@ Other enhancements
38
38
Backwards incompatible API changes
39
39
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40
40
41
+
42
+ Map on Index types now return other Index types
43
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44
+
41
45
- ``map`` on an ``Index`` now returns an ``Index``, not an array (:issue:`12766`)
42
46
43
47
.. ipython:: python
@@ -58,6 +62,102 @@ Backwards incompatible API changes
58
62
59
63
idx.map(lambda x: x * 2)
60
64
65
+ - ``map`` on an ``Index`` or ``MultiIndex`` returns the appropriate type depending on output dimensionality
66
+
67
+ .. ipython:: python
68
+
69
+ mi = MultiIndex.from_tuples([(1, 2), (2, 4)])
70
+ mi
71
+
72
+ Previous Behavior:
73
+
74
+ .. code-block:: ipython
75
+
76
+ In [5]: idx.map(lambda x: (x, x * 2))
77
+ Out[5]: array([(1, 2), (2, 4)], dtype=object)
78
+
79
+
80
+ In [6]: mi.map(lambda x: x[0])
81
+ Out[6]: array([1, 2])
82
+
83
+ New Behavior:
84
+
85
+ .. ipython:: python
86
+
87
+ idx.map(lambda x: (x, x * 2))
88
+
89
+ mi.map(lambda x: x[0])
90
+
91
+
92
+ - ``map`` on an ``CategoricalIndex`` now returns a ``CategoricalIndex``, not a Categorical
93
+
94
+ .. ipython:: python
95
+
96
+ ci = CategoricalIndex(list('ABABC'), categories=list('CBA'), ordered=True)
97
+ ci
98
+
99
+ Previous Behavior:
100
+
101
+ .. code-block:: ipython
102
+
103
+ In [7]: ci.map(lambda x: x.lower())
104
+ Out[7]:
105
+ [a, b, a, b, c]
106
+ Categories (3, object): [c < b < a]
107
+
108
+ New Behavior:
109
+
110
+ .. ipython:: python
111
+
112
+ ci.map(lambda x: x.lower())
113
+
114
+ - ``map`` on an ``DatetimeIndex`` or ``TimedeltaIndex`` now returns an ``Index`` instance
115
+
116
+ .. ipython:: python
117
+
118
+ dtidx = date_range(start='2016-01-01', end='2016-01-02')
119
+ dtidx
120
+
121
+ Previous Behavior:
122
+
123
+ .. code-block:: ipython
124
+
125
+ In [8]: dtidx.map(lambda x: x.day)
126
+ Out[8]: array([1, 2])
127
+
128
+ New Behavior:
129
+
130
+ .. ipython:: python
131
+
132
+ dtidx.map(lambda x: x.day)
133
+
134
+
135
+ - ``map`` on a Series withe datetime64 values may return int64 dtypes rather than int32
136
+
137
+ .. ipython:: python
138
+
139
+ s = Series(date_range('2011-01-02T00:00', '2011-01-02T02:00', freq='H').tz_localize('Asia/Tokyo'))
140
+ s
141
+
142
+ Previous Behavior:
143
+
144
+ .. code-block:: ipython
145
+
146
+ In [9]: s.map(lambda x: x.hour)
147
+ Out[9]:
148
+ 0 0
149
+ 1 1
150
+ 2 2
151
+ dtype: int32
152
+
153
+
154
+ New Behavior:
155
+
156
+ .. ipython:: python
157
+
158
+ s.map(lambda x: x.hour)
159
+
160
+
61
161
.. _whatsnew_0200.api:
62
162
63
163
0 commit comments