Skip to content

QST: best way to extend/subclass pandas.DataFrame #61362

Open
@rwijtvliet

Description

@rwijtvliet

Research

  • I have searched the [pandas] tag on StackOverflow for similar questions.

  • I have asked my usage related question on StackOverflow.

Link to question on StackOverflow

https://stackoverflow.com/questions/79594258/best-way-to-extend-subclass-pandas-dataframe

Question about pandas

I've written a package to work with energy-related timeseries. At its center is a class (PfLine) that is essentially a wrapper around pandas.DataFrame, and it implements various methods and properties that are also available on DataFrames - like .loc, .asfreq(), .index, etc.

I am currently in the middle of a rewrite of this package, and think it would be a good idea to have closer integration with pandas. This page lays out several possibilities, and I am unsure which route to take - and was hoping to find some sparring here.

Let me describe a bit what I'm trying to accomplish with the PfLine class:

  • Behaves like a DataFrame, with specific column names allowed and some data conversion (and validation) on initialisation.

  • Is immutable to avoid data from becoming inconsistent.

  • Has additional methods.

The methods could be directly under PfLine.method() or under e.g. df.pfl.method().

What is probably important: a way is needed for the user to specify a (still under development) configuration object (commodity) when initialising the PfLine. This object contains information used in coercing the data, e.g. what are the correct units and which timezones are allowed for the index.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions