Skip to content

Commit 21ebc0f

Browse files
nateyoderjorisvandenbossche
authored andcommitted
Clean up construction of Series with dictionary and datetime index
closes pandas-dev#14894 Fix usage of fast_multiget with index which was always throwing an exception that was then caught; add ASV that show slight improvement Author: Nate Yoder <[email protected]> Closes pandas-dev#14895 from nateyoder/series_dict_index and squashes the following commits: 56be091 [Nate Yoder] Update whatsnew and fix pep8 issue 5f05fdc [Nate Yoder] Fix usage of fast_multiget with index which was always throwing an exception that was then caught; add ASV that show slight improvement (cherry picked from commit e503d40)
1 parent bbb7686 commit 21ebc0f

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

asv_bench/benchmarks/series_methods.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,28 @@ def setup(self):
88
self.dr = pd.date_range(
99
start=datetime(2015,10,26),
1010
end=datetime(2016,1,1),
11-
freq='10s'
12-
) # ~500k long
11+
freq='50s'
12+
) # ~100k long
1313

1414
def time_series_constructor_no_data_datetime_index(self):
1515
Series(data=None, index=self.dr)
1616

1717

18+
class series_constructor_dict_data_datetime_index(object):
19+
goal_time = 0.2
20+
21+
def setup(self):
22+
self.dr = pd.date_range(
23+
start=datetime(2015, 10, 26),
24+
end=datetime(2016, 1, 1),
25+
freq='50s'
26+
) # ~100k long
27+
self.data = {d: v for d, v in zip(self.dr, range(len(self.dr)))}
28+
29+
def time_series_constructor_no_data_datetime_index(self):
30+
Series(data=self.data, index=self.dr)
31+
32+
1833
class series_isin_int64(object):
1934
goal_time = 0.2
2035

doc/source/whatsnew/v0.19.2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Performance Improvements
2222
~~~~~~~~~~~~~~~~~~~~~~~~
2323

2424
- Improved performance of ``.replace()`` (:issue:`12745`)
25+
- Improved performance ``Series`` creation with a datetime index and dictionary data (:issue:`14894`)
2526

2627

2728
.. _whatsnew_0192.enhancements.other:

pandas/core/series.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
187187
if len(data):
188188
# coerce back to datetime objects for lookup
189189
data = _dict_compat(data)
190-
data = lib.fast_multiget(data, index.astype('O'),
190+
data = lib.fast_multiget(data,
191+
index.asobject.values,
191192
default=np.nan)
192193
else:
193194
data = np.nan

0 commit comments

Comments
 (0)