Skip to content

Commit

Permalink
Store schema with metadata (#80)
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
WardLT authored Jul 1, 2024
1 parent 3351565 commit 0ed2397
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions batdata/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,11 @@ def __init__(self, metadata: Union[BatteryMetadata, dict] = None,
def validate_columns(self, allow_extra_columns: bool = True):
"""Determine whether the column types are appropriate
Parameters
----------
allow_extra_columns: bool
Whether to allow unexpected columns
Args:
allow_extra_columns: Whether to allow unexpected columns
Raises
------
ValueError
If the dataset fails validation
(ValueError): If the dataset fails validation
"""
for attr_name, schema in _subsets.items():
data = getattr(self, attr_name)
Expand All @@ -124,9 +120,7 @@ def validate(self) -> List[str]:
makes recommendations of improvements that one could make
to increase the re-usability of the data.
Returns
-------
List of str
Returns:
Recommendations to improve data re-use
"""
self.validate_columns()
Expand Down Expand Up @@ -193,6 +187,7 @@ def add_metadata(f: HDFStore):
if metadata != existing_metadata:
warnings.warn('Metadata already in HDF5 differs from new metadata')
f.root._v_attrs.metadata = metadata
f.root._v_attrs.schema = self.metadata.model_json_schema()

# Apply the metadata addition function
path_or_buf = stringify_path(path_or_buf)
Expand Down Expand Up @@ -292,7 +287,7 @@ def inspect_batdata_hdf(path_or_buf: Union[str, Path, HDFStore]) -> tuple[Batter
"""Extract the battery data and the prefixes of cells contained within an HDF5 file
Args:
path: Path to the HDF5 file, or HDFStore object
path_or_buf: Path to the HDF5 file, or HDFStore object
Returns:
- Metadata from this file
- List of names of batteries stored within the file
Expand Down

0 comments on commit 0ed2397

Please sign in to comment.