Skip to content

Commit 4559993

Browse files
committed
Address changes requested by @jreback
1 parent 425eb32 commit 4559993

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

asv_bench/benchmarks/series_methods.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ def setup(self, mapper, dtype):
157157
self.map_data = map_data
158158
elif mapper == 'dict':
159159
self.map_data = map_data.to_dict()
160-
else:
160+
elif mapper == 'lambda':
161161
map_dict = map_data.to_dict()
162162
self.map_data = lambda x: map_dict[x]
163+
else:
164+
raise NotImplementedError
163165

164166
self.s = Series(np.random.randint(0, map_size, 10000), dtype=dtype)
165167

doc/source/whatsnew/v0.25.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Performance Improvements
248248
- Improved performance of :meth:`pandas.core.groupby.GroupBy.quantile` (:issue:`20405`)
249249
- Improved performance of :meth:`read_csv` by faster tokenizing and faster parsing of small float numbers (:issue:`25784`)
250250
- Improved performance of :meth:`read_csv` by faster parsing of N/A and boolean values (:issue:`25804`)
251-
- Improved performance of :meth:`pandas.core.base.IndexOpsMixin._map_values` for dictionary mappers on categorical series by using the default series map method (:issue:`23785`)
251+
- Improved performance of :meth:`Series.map` for dictionary mappers on categorical series by mapping the categories instead of mapping all values (:issue:`23785`)
252252

253253
.. _whatsnew_0250.bug_fixes:
254254

pandas/core/base.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1196,16 +1196,15 @@ def _map_values(self, mapper, na_action=None):
11961196
if isinstance(mapper, ABCSeries):
11971197
# Since values were input this means we came from either
11981198
# a dict or a series and mapper should be an index
1199+
if is_categorical_dtype(self._values):
1200+
# use the built in categorical series mapper which saves
1201+
# time by mapping the categories instead of all values
1202+
return self._values.map(mapper)
11991203
if is_extension_type(self.dtype):
12001204
values = self._values
12011205
else:
12021206
values = self.values
12031207

1204-
if is_categorical_dtype(values):
1205-
# use the built in categorical series mapper which saves
1206-
# time by mapping the categories instead of all values
1207-
return values.map(mapper)
1208-
12091208
indexer = mapper.index.get_indexer(values)
12101209
new_values = algorithms.take_1d(mapper._values, indexer)
12111210

0 commit comments

Comments
 (0)