Skip to content

Instantly share code, notes, and snippets.

@wkerzendorf
Last active July 30, 2021 18:11
Show Gist options
  • Save wkerzendorf/52459080be83c7c382bac11ef9ac3195 to your computer and use it in GitHub Desktop.
Save wkerzendorf/52459080be83c7c382bac11ef9ac3195 to your computer and use it in GitHub Desktop.
class QSeries(pd.Series):
_metadata = ["unit", "descriptor"]
@property
def _constructor(self):
return QSeries
@property
def _constructor_expanddim(self):
return QDataFrame
class QDataFrame(pd.DataFrame):
# normal properties
_metadata = ["units"]
def __init__(self, *args, units=None, **kwargs):
super(QDataFrame, self).__init__(*args, **kwargs)
if units is None:
self.units = {}
else:
self.units = {key:value for key, value in units.items() if key in self.columns}
for col in self.columns:
if col in self.units:
self[col].unit = self.units[col]
@property
def _constructor(self):
return QDataFrame
@property
def _constructor_sliced(self):
return QSeries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment