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 4caf733 commit f2eb7f3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ authors = [{name="Statnett Datascience", email="Datascience.Drift@Statnett.no"}]
requires-python = ">=3.11"
dependencies = [
"httpx>=0.27.2",
"numpy>=2.1.1",
"numpy>=1.9.0",
"pandas>=2.2.3",
"pandera>=0.20.4",
"polyfactory>=2.17.0",
Expand Down
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.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)

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.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)

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
5 changes: 2 additions & 3 deletions tests/test_micro_t1_nl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from string import Template
from typing import Any

import pandas as pd
import pytest

import tests.t_utils.common as t_common
Expand Down Expand Up @@ -268,11 +267,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))
assert set(crd["epsg"]), {"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 f2eb7f3

Please sign in to comment.