- Change AuDaGeFrame back to extending DataFrame.
- Add type alias for "Frame" - list of dict for importing/exporting from DataFrame.
This commit is contained in:
@@ -10,9 +10,11 @@ desc: Extensions to DataFrame for AuDaGe purposes.
|
|||||||
|
|
||||||
from enum import StrEnum, auto
|
from enum import StrEnum, auto
|
||||||
|
|
||||||
import pandas as pd
|
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
|
type Frame = list[dict[str, any]]
|
||||||
|
"""A mutable data structure for importing from and exporting to DataFrames."""
|
||||||
|
|
||||||
|
|
||||||
class MandatoryColumns(StrEnum):
|
class MandatoryColumns(StrEnum):
|
||||||
"""Enum of columns that are mandatory for a valid AuDaGe DataFrame."""
|
"""Enum of columns that are mandatory for a valid AuDaGe DataFrame."""
|
||||||
@@ -23,21 +25,14 @@ class MandatoryColumns(StrEnum):
|
|||||||
COMMENT = auto()
|
COMMENT = auto()
|
||||||
|
|
||||||
|
|
||||||
class AuDaGeFrame:
|
class AuDaGeFrame(DataFrame):
|
||||||
"""DataFrame wrapped for AuDaGe purposes."""
|
"""DataFrame wrapped for AuDaGe purposes."""
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.dataframe = DataFrame(*args, **kwargs)
|
|
||||||
|
|
||||||
def missing_columns(self) -> list[MandatoryColumns]:
|
def missing_columns(self) -> list[MandatoryColumns]:
|
||||||
"""Return a list of mandatory columns that are missing from this
|
"""Return a list of mandatory columns that are missing from this
|
||||||
DataFrame.
|
DataFrame.
|
||||||
"""
|
"""
|
||||||
return [
|
return [label for label in MandatoryColumns if not label in self.columns]
|
||||||
label
|
|
||||||
for label in MandatoryColumns
|
|
||||||
if not label in self.dataframe.columns
|
|
||||||
]
|
|
||||||
|
|
||||||
def is_valid(self) -> bool:
|
def is_valid(self) -> bool:
|
||||||
"""Check whether the DataFrame contains all mandatory columns."""
|
"""Check whether the DataFrame contains all mandatory columns."""
|
||||||
|
|||||||
Reference in New Issue
Block a user