Change AuDaGeFrame from extending DataFrame to wrapping it.

This commit is contained in:
Silcantar
2026-09-14 14:41:45 -05:00
parent d68a42ed93
commit 1d61db067f
5 changed files with 22 additions and 9 deletions

View File

@@ -1,5 +1,11 @@
"""
AuDaGe
AuDaGe DataFrame extensions
name: audage_frame.py
by: Josh Lucas
date: 2026-09-14
desc: Extensions to DataFrame for AuDaGe purposes.
"""
from enum import StrEnum, auto
@@ -15,15 +21,22 @@ class MandatoryColumns(StrEnum):
COMMENT = auto()
class AuDaGeFrame(DataFrame):
"""DataFrame extended for AuDaGe purposes."""
class AuDaGeFrame:
"""DataFrame wrapped for AuDaGe purposes."""
def __init__(self, *args, **kwargs):
self.dataframe = DataFrame(*args, **kwargs)
def missing_columns(self) -> list[MandatoryColumns]:
"""Return a list of mandatory columns that are missing from this
DataFrame.
"""
return [
label
for label in MandatoryColumns
if not label in self.columns
if not label in self.dataframe.columns
]
def is_valid(self) -> bool:
"""Check whether the DataFrame contains all mandatory columns."""
return self.missing_columns() == []

View File

@@ -12,7 +12,7 @@ from enum import Enum, IntEnum
from pandas import Series, NA
from AuDaGe.audage import AuDaGeFrame
from AuDaGe.audage_frame import AuDaGeFrame
WORD_LENGTH = 16

View File

@@ -1,6 +1,6 @@
import unittest
from AuDaGe.audage import AuDaGeFrame
from AuDaGe.audage_frame import AuDaGeFrame
class TestAuDaGeFrame(unittest.TestCase):
def test_init(self):

View File

@@ -19,7 +19,7 @@ class TestIEC(unittest.TestCase):
iec_definitions = iec.iec_definitions()
self.assertTrue(iec_definitions.is_valid())
self.assertEqual(
iec_definitions.shape,
iec_definitions.dataframe.shape,
(len(iec.DataTypes.__members__), 7)
)

View File

@@ -27,11 +27,11 @@ class TestXSY(unittest.TestCase):
def test_export(self):
xsy = XSY()
xsy.read(os.path.join(IN_PATH, "hsps.xsy"), expand=False)
xsy.datablock.to_csv(
xsy.datablock.dataframe.to_csv(
os.path.join(OUT_PATH, "datablock.csv"),
index=False
)
xsy.definitions.to_csv(
xsy.definitions.dataframe.to_csv(
os.path.join(OUT_PATH, "defs.csv"),
index=False
)