Skip to content

Commit

Permalink
Register string datatype and update existing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Deepyaman Datta <[email protected]>
  • Loading branch information
deepyaman committed Aug 19, 2024
1 parent b79ec31 commit 55cf0f9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
22 changes: 22 additions & 0 deletions pandera/engines/ibis_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,25 @@ class Float64(DataType, dtypes.Float64):
"""Semantic representation of a :class:`dt.Float64`."""

type = dt.float64


###############################################################################
# nominal
###############################################################################


@Engine.register_dtype(
equivalents=[
str,
np.str_,
dtypes.String,
dtypes.String(),
dt.String,
dt.string,
]
)
@immutable
class String(DataType, dtypes.String):
"""Semantic representation of a :class:`dt.String`."""

type = dt.string
6 changes: 3 additions & 3 deletions pandera/engines/pandas_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ def __str__(self) -> str:
return dtypes.Decimal.__str__(self)


# ###############################################################################
# # nominal
# ###############################################################################
###############################################################################
# nominal
###############################################################################


@Engine.register_dtype(
Expand Down
6 changes: 3 additions & 3 deletions tests/ibis/test_ibis_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def t_schema_basic():
"""Basic Ibis table schema fixture."""
return DataFrameSchema(
{
# "string_col": Column(str),
"int_col": Column(int),
"string_col": Column(dt.String),
"int_col": Column(dt.Int64),
}
)

Expand All @@ -52,7 +52,7 @@ def test_required_columns():
schema = DataFrameSchema(
{
"a": Column(dt.Int64, required=True),
"b": Column(dt.Int64, required=False),
"b": Column(dt.String, required=False),
}
)
t = ibis.memtable(pd.DataFrame({"a": [1, 2, 3]}))
Expand Down
12 changes: 6 additions & 6 deletions tests/ibis/test_ibis_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@pytest.fixture
def t_model_basic():
class BasicModel(DataFrameModel):
# string_col: str
string_col: str
int_col: int

return BasicModel
Expand All @@ -21,7 +21,7 @@ class BasicModel(DataFrameModel):
def t_schema_basic():
return DataFrameSchema(
{
# "string_col": Column(dt.String),
"string_col": Column(dt.String),
"int_col": Column(dt.Int64),
}
)
Expand All @@ -38,14 +38,14 @@ def test_model_schema_equivalency(

def test_model_schema_equivalency_with_optional():
class ModelWithOptional(DataFrameModel):
# string_col: Optional[str]
int_col: Optional[int]
string_col: Optional[str]
int_col: int

schema = DataFrameSchema(
name="ModelWithOptional",
columns={
# "string_col": Column(dt.String, required=False),
"int_col": Column(dt.Int64, required=False),
"string_col": Column(dt.String, required=False),
"int_col": Column(dt.Int64),
},
)
assert ModelWithOptional.to_schema() == schema

0 comments on commit 55cf0f9

Please sign in to comment.