Skip to content

API: make CachedAccessor public in addition to register_dataframe_accessor #40103

Open
@jorisvandenbossche

Description

@jorisvandenbossche

In GeoPandas we added a plot accessor similar to the pandas one (so you can still access all the pandas plotting kinds, also from a GeoDataFrame where the default plot is a spatial map), see geopandas/geopandas#1465.

But, in that PR, we made use of pandas.core.accessor.CachedAccessor, which is how we add accessors in pandas under the hood:

pandas/pandas/core/frame.py

Lines 9730 to 9731 in ffa6e20

# Add plotting methods to DataFrame
plot = CachedAccessor("plot", pandas.plotting.PlotAccessor)

So in GeoPandas we basically copied the above code, but with our adapted GeoPlotAccessor.

The reason that we can't use the public way to add accessors with pd.api.extensions.register_dataframe_accessor is that we are overriding an existing accessor of pandas (intentionally).

So can we consider CachedAccessor to be "public"-like so it is fine for GeoPandas to use it? Or do we want to explicitly expose the class in the pandas.api.extensions namespace? Or can we change register_dataframe_accessor to allow it to override existing methods? (not sure we want to make that too easy)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions