Skip to content

Commit

Permalink
Keep _index_name
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Dec 16, 2024
1 parent dfa1c72 commit 007ee67
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
7 changes: 3 additions & 4 deletions python/ribasim/ribasim/geometry/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ class EdgeSchema(_GeoBaseSchema):
edge_type: Series[str] = pa.Field(default="flow")
geometry: GeoSeries[LineString] = pa.Field(default=None, nullable=True)

@pa.dataframe_parser
def _name_index(cls, df):
df.index.name = "edge_id"
return df
@classmethod
def _index_name(self) -> str:
return "edge_id"


class EdgeTable(SpatialTableModel[EdgeSchema]):
Expand Down
7 changes: 3 additions & 4 deletions python/ribasim/ribasim/geometry/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ class NodeSchema(_GeoBaseSchema):
)
geometry: GeoSeries[Point] = pa.Field(default=None, nullable=True)

@pa.dataframe_parser
def _name_index(cls, df):
df.index.name = "node_id"
return df
@classmethod
def _index_name(self) -> str:
return "node_id"


class NodeTable(SpatialTableModel[NodeSchema]):
Expand Down
8 changes: 5 additions & 3 deletions python/ribasim/ribasim/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class Config:
add_missing_columns = True
coerce = True

@classmethod
def _index_name(self) -> str:
return "fid"

@pa.dataframe_parser
def _name_index(cls, df):
# Node and Edge have different index names, avoid running both parsers
if cls.__name__ not in ("NodeSchema", "EdgeSchema"):
df.index.name = "fid"
df.index.name = cls._index_name()
return df

@classmethod
Expand Down
8 changes: 5 additions & 3 deletions utils/templates/schemas.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class _BaseSchema(pa.DataFrameModel):
add_missing_columns = True
coerce = True

@classmethod
def _index_name(self) -> str:
return "fid"

@pa.dataframe_parser
def _name_index(cls, df):
# Node and Edge have different index names, avoid running both parsers
if cls.__name__ not in ("NodeSchema", "EdgeSchema"):
df.index.name = "fid"
df.index.name = cls._index_name()
return df

@classmethod
Expand Down

0 comments on commit 007ee67

Please sign in to comment.