-
-
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
API: _constructor and subclasses #32638
Comments
If we were to go for option 2, why not just get rid of _constructor and use |
I don't think we need to require this (we also don't require When having a DataFrame subclass, not every operation in pandas necessarily needs to return that subclass, depending on your use case and characteristics of your subclass. |
Whether to change the default (item 2), that might make sense (it seems a more sensible default, maybe). If we want to do larger changes on how this |
Another candidate criterion that I'm finding in #33357 would be desirable: make this a class attribute instead of an instance attribute, like Granted, the semantics of implementing that are pretty ugly. |
@jorisvandenbossche you mentioned geopandas returns a callable instead of a class. How difficult would it be to change that? Are we aware of any other downstream libraries that do that? |
See my explanation above #32638 (comment), about that this is actually a feature for geopandas that we don't have to return a class. I suppose I could make a dummy class with a So my question back is: what are the use cases for requiring it to be a class? (apart from the PR with the |
Just grepping for |
That was recently added: #33884 |
Followup to #31925.
Over there, we removed
_ensure_type
because it broke things likeHowever, I don't think that example is very compelling. It's strange for MyDataFrame.reindex to return anything other than MyDataFrame. The root cause is MyDataFrame._constructor returning
DataFrame
, rather thanMyDataFrame
.I think we should somehow get subclasses to have their _constructor return something that returns their subclass. We can
DataFrame._constructor
DataFrame._constructor
to returntype(self)
2 is nicer, but it requires that the subclasses
__init__
method be compatible enough with DataFrame's. It's probably safe to assume that, but it might be an API breaking change.The text was updated successfully, but these errors were encountered: