Skip to content

Commit

Permalink
Update to Pydantic v2 (#42)
Browse files Browse the repository at this point in the history
* Add conda environment

* Increment to Pydantic v2, update notations

* Flake8 fix
  • Loading branch information
WardLT authored Feb 5, 2024
1 parent da68a97 commit ae56b3d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
26 changes: 13 additions & 13 deletions batdata/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ class BatteryMetadata(BaseModel, extra=Extra.allow):
"""

# Miscellaneous fields
name: str = Field(None, description="Name of the cell. Any format for the name is acceptable,"
" as it is intended to be used by the battery data provider.")
comments: str = Field(None, description="Long form comments describing the test")
name: Optional[str] = Field(None, description="Name of the cell. Any format for the name is acceptable,"
" as it is intended to be used by the battery data provider.")
comments: Optional[str] = Field(None, description="Long form comments describing the test")
version: str = Field(__version__, description="Version of this metadata")

# Fields that describe the test protocol
cycler: str = Field(None, description='Name of the cycling machine')
start_date: date = Field(None, description="Date the initial test on the cell began")
set_temperature: float = Field(None, description="Set temperature for the battery testing equipment. Units: C")
schedule: str = Field(None, description="Schedule file used for the cycling machine")
cycler: Optional[str] = Field(None, description='Name of the cycling machine')
start_date: Optional[date] = Field(None, description="Date the initial test on the cell began")
set_temperature: Optional[float] = Field(None, description="Set temperature for the battery testing equipment. Units: C")
schedule: Optional[str] = Field(None, description="Schedule file used for the cycling machine")

# Field that describe the battery assembly
battery: Optional[BatteryDescription] = Field(None, description="Description of the battery being tested")

# Fields that describe the source of data
source: str = Field(None, description="Organization who created this data")
dataset_name: str = Field(None, description="Name of a larger dataset this data is associated with")
authors: List[Tuple[str, str]] = Field(None, description="Name and affiliation of each of the authors of the data. First and last names")
associated_ids: List[AnyUrl] = Field(None, description="Any identifiers associated with this data file."
" Identifiers can be any URI, such as DOIs of associated"
" paper or HTTP addresses of associated websites")
source: Optional[str] = Field(None, description="Organization who created this data")
dataset_name: Optional[str] = Field(None, description="Name of a larger dataset this data is associated with")
authors: Optional[List[Tuple[str, str]]] = Field(None, description="Name and affiliation of each of the authors of the data. First and last names")
associated_ids: Optional[List[AnyUrl]] = Field(None, description="Any identifiers associated with this data file."
" Identifiers can be any URI, such as DOIs of associated"
" paper or HTTP addresses of associated websites")

# Description of additional columns
raw_data_columns: Dict[str, str] = Field(default_factory=dict, description='Descriptions of non-standard columns in the raw data')
Expand Down
4 changes: 2 additions & 2 deletions batdata/schemas/cycling.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def validate_dataframe(cls, data: DataFrame, allow_extra_columns: bool = True):
# Get the data type for the column
if '$ref' in col_schema['items']:
ref_name = col_schema['items']['$ref'].split("/")[-1]
col_type = schema['definitions'][ref_name]['type']
col_type = schema['$defs'][ref_name]['type']
else:
col_type = col_schema['items']['type']

Expand Down Expand Up @@ -134,7 +134,7 @@ class RawData(ColumnSchema):
" or resting.")
file_number: List[int] = Field(None, description="Used if test data is stored in multiple files. Number represents "
"the index of the file. All indices should be nonnegative and "
"monotonically increasing", ge=0, monotonic=True)
"monotonically increasing", monotonic=True)
test_time: List[float] = Field(..., description="Time from the beginning of the cycling test. Times must be "
"nonnegative and monotonically increasing. Units: s",
monotonic=True)
Expand Down
3 changes: 3 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Development Files

Files useful to setting up a development environment
11 changes: 11 additions & 0 deletions dev/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Conda environment file
name: batdata
channels:
- defaults
dependencies:
- python==3.9.*

# For now, use Pip for everything
- pip
- pip:
- -e ..[test]
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "battery-data-toolkit"
version = "0.1.1"
version = "0.2.0"
description = "Utilities for reading and manipulating battery testing data"
readme = "README.md"
requires-python = ">=3.9"
Expand All @@ -14,7 +14,7 @@ authors = [
dependencies = [
"pandas > 1.0",
"scipy > 1.3",
"pydantic < 2",
"pydantic == 2.*",
"tables > 3.6",
"h5py == 3.*",
"scythe-extractors >= 0.1",
Expand Down

0 comments on commit ae56b3d

Please sign in to comment.