pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
42.58k stars 17.57k forks source link

ENH: read_parquet as a class method #58303

Open davetapley opened 2 months ago

davetapley commented 2 months ago

Feature Type

Problem Description

I wish I could use read_parquet on a DataFrame subclass and it would Just Work.

Currently I have to:


class Foo(pd.DataFrame):
    # stuff from
    # https://pandas.pydata.org/pandas-docs/stable/development/extending.html#override-constructor-properties
    ....

df = read_parquet(file)
foo = Foo(df)
foo.attrs = df.attrs
# maybe I missed something else?

Feature Description

A Foo.read_parquet(file) which would return a Foo with attrs and everything else.

Alternative Solutions

As shown in description I can manually copy attrs, but it's not idea.

Additional Context

Related to:

jbrockmendel commented 2 months ago

For the most part we want either pd.function or DataFrame.method, not both.