Skip to content

Commit

Permalink
feat!: simplify schema for coordinate dataframe. Use regular data typ…
Browse files Browse the repository at this point in the history
…es (str instead of CategoricalDtype) and give coordinates as floats
  • Loading branch information
davidkleiven committed Oct 15, 2024
1 parent 9e428eb commit ccae4d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/cimsparql/data_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime as dt
from typing import Self

import pandas as pd
import pandera as pa

Check failure on line 4 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 4 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 4 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera" could not be resolved (reportMissingImports)

Check failure on line 4 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera" could not be resolved (reportMissingImports)
from pandera.typing import DataFrame, Index, Series

Check failure on line 5 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 5 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 5 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.11

Import "pandera.typing" could not be resolved (reportMissingImports)

Check failure on line 5 in src/cimsparql/data_models.py

View workflow job for this annotation

GitHub Actions / ubuntu-latest / 3.12

Import "pandera.typing" could not be resolved (reportMissingImports)

Expand Down Expand Up @@ -189,10 +188,10 @@ class TransfConToConverterSchema(NamedResourceSchema):

class CoordinatesSchema(JsonSchemaOut):
mrid: Series[str] = pa.Field()
x: Series[str] = pa.Field()
y: Series[str] = pa.Field()
epsg: Series[pd.CategoricalDtype] = pa.Field()
rdf_type: Series[pd.CategoricalDtype] = pa.Field()
x: Series[float] = pa.Field()
y: Series[float] = pa.Field()
epsg: Series[str] = pa.Field()
rdf_type: Series[str] = pa.Field()


CoordinatesDataFrame = DataFrame[CoordinatesSchema]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_micro_t1_nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@ def test_coordinates(test_model: t_common.ModelTest):
assert test_model.model
model = test_model.model
crd = model.coordinates()
pd.testing.assert_index_equal(crd["epsg"].cat.categories, pd.Index(["4326"], dtype=str))
pd.testing.assert_series_equal(crd["epsg"], pd.Series(["4326"]))

cim = model.client.prefixes["cim"]
categories = {f"{cim}ACLineSegment", f"{cim}Substation"}
assert crd["rdf_type"].cat.categories.difference(categories).empty
assert set(crd["rdf_type"]).difference(categories) == set()

assert len(crd) == 49
coordinates = crd.astype({"x": float, "y": float})
Expand Down

0 comments on commit ccae4d6

Please sign in to comment.