Skip to content

DEPR: require _constructor/_constructor_sliced to return a class #51772

Open
@jbrockmendel

Description

@jbrockmendel

(DataFrame|Series)Subclass._constructor(_sliced|_expanddim)? does not currently need to return a class. It can return a callable. This means that we cannot write obj._constructor_sliced.some_method, which has caused bugs/confusion at times. Most recently this surprised a contributor in #51765 and makes the fix there less straightforward.

AFAIK the only/main subclass that relies on this is geopandas, which inspects the arguments to decide which subclass to use. IIUC this could be accomplished with a __new__ method just as easily. cc @jorisvandenbossche

We could even go as far as deprecating _constructor entirely in favor of type(self) and just having _constructor_sliced/_constructor_expanddim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeprecateFunctionality to remove in pandasNeeds DiscussionRequires discussion from core team before further actionSubclassingSubclassing pandas objects

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions