-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
[ArrayManager] Add Series._as_manager (consolidate with DataFrame) #40304
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
[ArrayManager] Add Series._as_manager (consolidate with DataFrame) #40304
Conversation
new_mgr = arrays_to_mgr( | ||
mgr.arrays, mgr.axes[0], mgr.axes[1], mgr.axes[0], typ="block" | ||
) | ||
if mgr.ndim == 2: |
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.
can you make elif/else
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.
I personally wouldn't find that an improvement in readability. Now it's very clearly separated into two cases (manager already has the same type -> use as is, or else the manager needs to be converted)
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.
using nested elif/if is an anti-pattern
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.
It's only an anti-pattern if it's deeply nested and hampering readability. In this case, it makes the code easier to understand IMO.
elif typ == "array": | ||
if isinstance(mgr, ArrayManager): | ||
new_mgr = mgr | ||
else: | ||
arrays = [mgr.iget_values(i).copy() for i in range(len(mgr.axes[0]))] | ||
new_mgr = ArrayManager(arrays, [mgr.axes[1], mgr.axes[0]]) | ||
if mgr.ndim == 2: |
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.
same
Thanks |
Move the
_as_manager
helper togeneric.py
, and ensure it works for Series as well