diff --git a/asv_bench/benchmarks/series_methods.py b/asv_bench/benchmarks/series_methods.py index 4e368c6d7cde2..c164f3ddb2d6f 100644 --- a/asv_bench/benchmarks/series_methods.py +++ b/asv_bench/benchmarks/series_methods.py @@ -15,6 +15,21 @@ def time_series_constructor_no_data_datetime_index(self): Series(data=None, index=self.dr) +class series_constructor_dict_data_datetime_index(object): + goal_time = 0.2 + + def setup(self): + self.dr = pd.date_range( + start=datetime(2015, 10, 26), + end=datetime(2016, 1, 1), + freq='10s' + ) # ~500k long + self.data = {d: v for d, v in zip(self.dr, range(len(self.dr)))} + + def time_series_constructor_no_data_datetime_index(self): + Series(data=self.data, index=self.dr) + + class series_isin_int64(object): goal_time = 0.2 diff --git a/doc/source/whatsnew/v0.19.2.txt b/doc/source/whatsnew/v0.19.2.txt index 82d43db667550..d862f734dfb85 100644 --- a/doc/source/whatsnew/v0.19.2.txt +++ b/doc/source/whatsnew/v0.19.2.txt @@ -22,6 +22,7 @@ Performance Improvements ~~~~~~~~~~~~~~~~~~~~~~~~ - Improved performance of ``.replace()`` (:issue:`12745`) +- Improved performance ``Series`` creation with a datetime index and dictionary data (:issue:`14894`) .. _whatsnew_0192.enhancements.other: diff --git a/pandas/core/series.py b/pandas/core/series.py index 7018865e5b3ec..f656d72296e3a 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -188,7 +188,8 @@ def __init__(self, data=None, index=None, dtype=None, name=None, if len(data): # coerce back to datetime objects for lookup data = _dict_compat(data) - data = lib.fast_multiget(data, index.astype('O'), + data = lib.fast_multiget(data, + index.asobject.values, default=np.nan) else: data = np.nan