Change AuDaGeFrame from extending DataFrame to wrapping it.
This commit is contained in:
@@ -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
|
from enum import StrEnum, auto
|
||||||
@@ -15,15 +21,22 @@ class MandatoryColumns(StrEnum):
|
|||||||
COMMENT = auto()
|
COMMENT = auto()
|
||||||
|
|
||||||
|
|
||||||
class AuDaGeFrame(DataFrame):
|
class AuDaGeFrame:
|
||||||
"""DataFrame extended 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
|
||||||
|
DataFrame.
|
||||||
|
"""
|
||||||
return [
|
return [
|
||||||
label
|
label
|
||||||
for label in MandatoryColumns
|
for label in MandatoryColumns
|
||||||
if not label in self.columns
|
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."""
|
||||||
return self.missing_columns() == []
|
return self.missing_columns() == []
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from enum import Enum, IntEnum
|
|||||||
|
|
||||||
from pandas import Series, NA
|
from pandas import Series, NA
|
||||||
|
|
||||||
from AuDaGe.audage import AuDaGeFrame
|
from AuDaGe.audage_frame import AuDaGeFrame
|
||||||
|
|
||||||
|
|
||||||
WORD_LENGTH = 16
|
WORD_LENGTH = 16
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from AuDaGe.audage import AuDaGeFrame
|
from AuDaGe.audage_frame import AuDaGeFrame
|
||||||
|
|
||||||
class TestAuDaGeFrame(unittest.TestCase):
|
class TestAuDaGeFrame(unittest.TestCase):
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
@@ -19,7 +19,7 @@ class TestIEC(unittest.TestCase):
|
|||||||
iec_definitions = iec.iec_definitions()
|
iec_definitions = iec.iec_definitions()
|
||||||
self.assertTrue(iec_definitions.is_valid())
|
self.assertTrue(iec_definitions.is_valid())
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
iec_definitions.shape,
|
iec_definitions.dataframe.shape,
|
||||||
(len(iec.DataTypes.__members__), 7)
|
(len(iec.DataTypes.__members__), 7)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ class TestXSY(unittest.TestCase):
|
|||||||
def test_export(self):
|
def test_export(self):
|
||||||
xsy = XSY()
|
xsy = XSY()
|
||||||
xsy.read(os.path.join(IN_PATH, "hsps.xsy"), expand=False)
|
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"),
|
os.path.join(OUT_PATH, "datablock.csv"),
|
||||||
index=False
|
index=False
|
||||||
)
|
)
|
||||||
xsy.definitions.to_csv(
|
xsy.definitions.dataframe.to_csv(
|
||||||
os.path.join(OUT_PATH, "defs.csv"),
|
os.path.join(OUT_PATH, "defs.csv"),
|
||||||
index=False
|
index=False
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user