Skip to content

Clean up construction of Series with dictionary and datetime index #14895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions asv_bench/benchmarks/series_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make this 1/10th the size (it will still show the differences), just generally don't want to have have 3 second functions. ping when you push as the rest is ok.

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

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.19.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 2 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down