Skip to content

Commit

Permalink
feat(rules): allow non-unique area
Browse files Browse the repository at this point in the history
  • Loading branch information
nialov committed Sep 6, 2023
1 parent d89c703 commit 370741b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def df_with_row(

srs = pd.Series(data=row.values(), index=row.keys(), name=area_name)

df = pd.concat([df, srs.to_frame().T])
concat_dfs = [srs.to_frame().T]
if df is not None:
concat_dfs.append(df)
df = pd.concat(concat_dfs)

traces_path = (
Path(rules.PathNames.UNORGANIZED.value) / f"{traces_name}.{rules.FILETYPE}"
Expand Down
25 changes: 25 additions & 0 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""
Tests for rules.py.
"""
from contextlib import nullcontext

import pandas as pd
import pandera as pa
import pytest
from hypothesis import given

import tests
from tracerepo import rules


@given(tests.name_regex(geom_type=None))
Expand All @@ -14,3 +19,23 @@ def test_filename_regex(name: str):
"""
assert isinstance(name, str)
assert len(name) >= 2


@pytest.mark.parametrize(
"df,raises",
[
(pd.DataFrame({}), pytest.raises(pa.errors.SchemaError)),
(tests.df_with_row(None)[0], nullcontext()),
(pd.concat([tests.df_with_row(None)[0]] * 2), nullcontext()),
],
)
def test_database_schema(df, raises):
"""
Test database_schema.
"""
result = None
with raises:
result = rules.database_schema().validate(df)
if result is None:
return
assert isinstance(result, pd.DataFrame)
2 changes: 1 addition & 1 deletion tracerepo/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def database_schema() -> pa.DataFrameSchema:
"""
schema = pa.DataFrameSchema(
# Index is the area name
index=pa.Index(**name_column_kwargs(unique=True, geom_type=ColumnNames.AREA)),
index=pa.Index(**name_column_kwargs(unique=False, geom_type=ColumnNames.AREA)),
coerce=True,
# Columns
columns={
Expand Down

0 comments on commit 370741b

Please sign in to comment.