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

ENH: Adding pd.options.observed_true_on_all_groupbys #49904

Closed
1 of 3 tasks
PMLP-novo opened this issue Nov 25, 2022 · 3 comments
Closed
1 of 3 tasks

ENH: Adding pd.options.observed_true_on_all_groupbys #49904

PMLP-novo opened this issue Nov 25, 2022 · 3 comments
Labels
Categorical Categorical Data Type Enhancement Groupby Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@PMLP-novo
Copy link

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

After adding observed = True to allot of my group by's in order to avoid memory crashes. I wish to be able to change the default in away that I can put on of my script.

Feature Description

I want to be able to set:

import pandas as pd
pd.options.observed_true_on_all_groupbys

I know it will make the following:
df.groupby("var",observed=False)
not being respected. But I don't think anybody would want that and I have tried to make it as clear as posible in the naming

Alternative Solutions

Impliment #43999
Or make a warning on memory usage if there is more than 100,000,000 buckets used and there is less than 1,000,000 unique values in any of the variables For example.

Additional Context

Allot of people are facing this problem https://stackoverflow.com/questions/50051210/avoiding-memory-issues-for-groupby-on-large-pandas-dataframe

@PMLP-novo PMLP-novo added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Nov 25, 2022
@PMLP-novo
Copy link
Author

PMLP-novo commented Nov 25, 2022

An alternative suggestion could be to that the observed was determined at runtime by default. So if there will be created more groups than lets say 100,000,000 if groups are created in the Cartesian way, then we automatically change to observed = True.
I the code this should be having the default observed = None. This solution will be backwards compatible if users have set observed.

@rhshadrach
Copy link
Member

Thanks for the request. I agree that having the default be observed=False is a bit of a pain point, but I'm -1 on making code df.groupby("var",observed=False) do anything but have observed=False as this would be very counter-intuitive. I'm also -1 on having magic numbers as cutoff points that change the behavior for the same reason.

I think the proper resolution is to change the default to True as in #43999

@rhshadrach rhshadrach added Groupby Categorical Categorical Data Type labels Nov 25, 2022
@mroeschke
Copy link
Member

Agreed that the proper resolution in #43999 is preferable than having options that side-step behavior. I think since we had #35967 previously as an attempt to change this, and with 2.0 being the next release, I think we may be more open to changing the default. Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Enhancement Groupby Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

3 participants