Skip to content

[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

Merged
merged 2 commits into from
Mar 16, 2021

Conversation

jorisvandenbossche
Copy link
Member

Move the _as_manager helper to generic.py, and ensure it works for Series as well

@jorisvandenbossche jorisvandenbossche added the Internals Related to non-user accessible pandas implementation label Mar 8, 2021
new_mgr = arrays_to_mgr(
mgr.arrays, mgr.axes[0], mgr.axes[1], mgr.axes[0], typ="block"
)
if mgr.ndim == 2:
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 elif/else

Copy link
Member Author

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)

Copy link
Contributor

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

Copy link
Member Author

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@jorisvandenbossche jorisvandenbossche added this to the 1.3 milestone Mar 16, 2021
@jreback jreback merged commit 5dc5b1a into pandas-dev:master Mar 16, 2021
@jorisvandenbossche jorisvandenbossche deleted the am-series-as-manager branch March 16, 2021 14:36
@jorisvandenbossche
Copy link
Member Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants