From ae56b3dcf2d57d39a1a0bf60bee3db12f3ea1271 Mon Sep 17 00:00:00 2001 From: Logan Ward Date: Mon, 5 Feb 2024 15:25:09 -0500 Subject: [PATCH] Update to Pydantic v2 (#42) * Add conda environment * Increment to Pydantic v2, update notations * Flake8 fix --- batdata/schemas/__init__.py | 26 +++++++++++++------------- batdata/schemas/cycling.py | 4 ++-- dev/README.md | 3 +++ dev/environment.yml | 11 +++++++++++ pyproject.toml | 4 ++-- 5 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 dev/README.md create mode 100644 dev/environment.yml diff --git a/batdata/schemas/__init__.py b/batdata/schemas/__init__.py index 2a8ccab..2e82120 100644 --- a/batdata/schemas/__init__.py +++ b/batdata/schemas/__init__.py @@ -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') diff --git a/batdata/schemas/cycling.py b/batdata/schemas/cycling.py index 209f93d..3fc0fdb 100644 --- a/batdata/schemas/cycling.py +++ b/batdata/schemas/cycling.py @@ -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'] @@ -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) diff --git a/dev/README.md b/dev/README.md new file mode 100644 index 0000000..48b8903 --- /dev/null +++ b/dev/README.md @@ -0,0 +1,3 @@ +# Development Files + +Files useful to setting up a development environment diff --git a/dev/environment.yml b/dev/environment.yml new file mode 100644 index 0000000..8e78c3c --- /dev/null +++ b/dev/environment.yml @@ -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] diff --git a/pyproject.toml b/pyproject.toml index bf868fd..7eb131f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" @@ -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",