-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
REF: remove block access in groupby libreduction Series(Bin)Grouper #40199
Changes from 1 commit
2dfeffb
adf5e81
450e800
1df3593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,16 +59,20 @@ cdef class _BaseGrouper: | |
cached_typ = self.typ( | ||
vslider.buf, dtype=vslider.buf.dtype, index=cached_ityp, name=self.name | ||
) | ||
self.has_block = hasattr(cached_typ._mgr, "_block") | ||
else: | ||
# See the comment in indexes/base.py about _index_data. | ||
# We need this for EA-backed indexes that have a reference | ||
# to a 1-d ndarray like datetime / timedelta / period. | ||
object.__setattr__(cached_ityp, '_index_data', islider.buf) | ||
cached_ityp._engine.clear_mapping() | ||
cached_ityp._cache.clear() # e.g. inferred_freq must go | ||
object.__setattr__(cached_typ._mgr._block, 'values', vslider.buf) | ||
object.__setattr__(cached_typ._mgr._block, 'mgr_locs', | ||
slice(len(vslider.buf))) | ||
if self.has_block: | ||
object.__setattr__(cached_typ._mgr._block, 'values', vslider.buf) | ||
object.__setattr__(cached_typ._mgr._block, 'mgr_locs', | ||
slice(len(vslider.buf))) | ||
else: | ||
cached_typ._mgr.arrays[0] = vslider.buf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could probably replace this full if/else block with a single But I assume that, currently, we don't use a plain python attribute setting but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the newer commit I pushed does this change, and is thus now using I did some timings with a specific function that uses the SeriesGrouper with many labels + a cheap dummy function (adapted from the same benchmark case as I have been using for the other groupby PRs: #40178 (comment)):
And repeating this several times switching back and forth between this version and master, I don't see any difference. A representative timing was:
|
||
object.__setattr__(cached_typ, '_index', cached_ityp) | ||
object.__setattr__(cached_typ, 'name', self.name) | ||
|
||
|
@@ -108,6 +112,7 @@ cdef class SeriesBinGrouper(_BaseGrouper): | |
cdef public: | ||
ndarray arr, index, dummy_arr, dummy_index | ||
object values, f, bins, typ, ityp, name | ||
bint has_block | ||
|
||
def __init__(self, object series, object f, object bins): | ||
|
||
|
@@ -201,6 +206,7 @@ cdef class SeriesGrouper(_BaseGrouper): | |
cdef public: | ||
ndarray arr, index, dummy_arr, dummy_index | ||
object f, labels, values, typ, ityp, name | ||
bint has_block | ||
|
||
def __init__(self, object series, object f, object labels, | ||
Py_ssize_t ngroups): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might get a small boost by setting _mgr_locs to BlockPlacement(slice(...)) instead of going through the mgr_locs property