Skip to content
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

PERF: don't materialize arrays on checking in groupby #16413

Merged
merged 1 commit into from
May 22, 2017
Merged
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
9 changes: 9 additions & 0 deletions asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ def setup(self):
self.dates = (np.datetime64('now') + self.offsets)
self.df = DataFrame({'key1': np.random.randint(0, 500, size=self.n), 'key2': np.random.randint(0, 100, size=self.n), 'value1': np.random.randn(self.n), 'value2': np.random.randn(self.n), 'value3': np.random.randn(self.n), 'dates': self.dates, })

N = 1000000
self.draws = pd.Series(np.random.randn(N))
labels = pd.Series(['foo', 'bar', 'baz', 'qux'] * (N // 4))
self.cats = labels.astype('category')

def time_groupby_multi_size(self):
self.df.groupby(['key1', 'key2']).size()

Expand All @@ -377,6 +382,10 @@ def time_groupby_dt_size(self):
def time_groupby_dt_timegrouper_size(self):
self.df.groupby(TimeGrouper(key='dates', freq='M')).size()

def time_groupby_size(self):
self.draws.groupby(self.cats).size()



#----------------------------------------------------------------------
# groupby with a variable value for ngroups
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Performance Improvements
- Performance regression fix when indexing with a list-like (:issue:`16285`)
- Performance regression fix for MultiIndexes (:issue:`16319`, :issue:`16346`)
- Improved performance of ``.clip()`` with scalar arguments (:issue:`15400`)

- Improved performance of groupby with categorical groupers (:issue:`16413`)

.. _whatsnew_0202.bug_fixes:

Expand Down
1 change: 0 additions & 1 deletion pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,6 @@ def get_loc(self, key, method=None, tolerance=None):
if tolerance is not None:
raise ValueError('tolerance argument only valid if using pad, '
'backfill or nearest lookups')
key = _values_from_object(key)
try:
return self._engine.get_loc(key)
except KeyError:
Expand Down