Skip to content

Commit 342d6c5

Browse files
committed
Implement binary and boolean types (and test them)
Signed-off-by: Deepyaman Datta <[email protected]>
1 parent 49cee21 commit 342d6c5

File tree

4 files changed

+67
-8
lines changed

4 files changed

+67
-8
lines changed

pandera/engines/ibis_engine.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ def dtype(cls, data_type: Any) -> dtypes.DataType:
8787
return engine.Engine.dtype(cls, np_dtype)
8888

8989

90+
###############################################################################
91+
# boolean
92+
###############################################################################
93+
94+
95+
@Engine.register_dtype(
96+
equivalents=[
97+
bool,
98+
np.bool_,
99+
dtypes.Bool,
100+
dtypes.Bool(),
101+
dt.Boolean,
102+
dt.boolean,
103+
]
104+
)
105+
@immutable
106+
class Bool(DataType, dtypes.Bool):
107+
"""Semantic representation of a :class:`dt.Boolean`."""
108+
109+
type = dt.boolean
110+
111+
90112
###############################################################################
91113
# signed integer
92114
###############################################################################
@@ -262,6 +284,23 @@ class String(DataType, dtypes.String):
262284
type = dt.string
263285

264286

287+
@Engine.register_dtype(
288+
equivalents=[
289+
bytes,
290+
np.bytes_,
291+
dtypes.Binary,
292+
dtypes.Binary(),
293+
dt.Binary,
294+
dt.binary,
295+
]
296+
)
297+
@immutable
298+
class Binary(DataType, dtypes.Binary):
299+
"""Semantic representation of a :class:`dt.Binary`."""
300+
301+
type = dt.binary
302+
303+
265304
###############################################################################
266305
# temporal
267306
###############################################################################

tests/ibis/test_ibis_builtin_checks.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ class TestEqualToCheck(BaseClass):
157157
"test_expression": datetime.timedelta(100, 10, 1),
158158
}
159159

160+
sample_boolean_data = {
161+
"test_pass_data": [("foo", True), ("bar", True)],
162+
"test_fail_data": [("foo", False), ("bar", False)],
163+
"test_expression": True,
164+
}
165+
160166
def pytest_generate_tests(self, metafunc):
161167
"""This function passes the parameter for each function based on parameter from get_data_param function"""
162168
# called once per each test function
@@ -184,6 +190,12 @@ def get_data_param(self):
184190
{"datatype": dt.Int32, "data": self.sample_numeric_data},
185191
{"datatype": dt.Int64, "data": self.sample_numeric_data},
186192
{"datatype": dt.String, "data": self.sample_string_data},
193+
{
194+
"datatype": dt.Binary,
195+
"data": self.convert_data(
196+
self.sample_string_data, "binary"
197+
),
198+
},
187199
{
188200
"datatype": dt.Float32,
189201
"data": self.convert_data(
@@ -216,6 +228,7 @@ def get_data_param(self):
216228
"datatype": dt.Interval(unit="us"),
217229
"data": self.sample_duration_data,
218230
},
231+
{"datatype": dt.Boolean, "data": self.sample_boolean_data},
219232
]
220233
}
221234

@@ -302,6 +315,12 @@ class TestNotEqualToCheck(BaseClass):
302315
),
303316
}
304317

318+
sample_boolean_data = {
319+
"test_pass_data": [("foo", True), ("bar", True)],
320+
"test_fail_data": [("foo", False), ("bar", True)],
321+
"test_expression": False,
322+
}
323+
305324
def pytest_generate_tests(self, metafunc):
306325
"""This function passes the parameter for each function based on parameter from get_data_param function"""
307326
# called once per each test function
@@ -361,6 +380,7 @@ def get_data_param(self):
361380
"datatype": dt.Interval(unit="us"),
362381
"data": self.sample_duration_data,
363382
},
383+
{"datatype": dt.Boolean, "data": self.sample_boolean_data},
364384
]
365385
}
366386

tests/polars/test_polars_builtin_checks.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,6 @@ class TestEqualToCheck(BaseClass):
192192
"test_expression": "a",
193193
}
194194

195-
sample_boolean_data = {
196-
"test_pass_data": [("foo", True), ("bar", True)],
197-
"test_fail_data": [("foo", False), ("bar", False)],
198-
"test_expression": True,
199-
}
200-
201195
sample_array_data = {
202196
"test_pass_data": [("foo", ["a"]), ("bar", ["a"])],
203197
"test_fail_data": [("foo", ["a"]), ("bar", ["b"])],
@@ -216,6 +210,12 @@ class TestEqualToCheck(BaseClass):
216210
"test_expression": datetime.timedelta(100, 10, 1),
217211
}
218212

213+
sample_boolean_data = {
214+
"test_pass_data": [("foo", True), ("bar", True)],
215+
"test_fail_data": [("foo", False), ("bar", False)],
216+
"test_expression": True,
217+
}
218+
219219
def pytest_generate_tests(self, metafunc):
220220
"""This function passes the parameter for each function based on parameter from get_data_param function"""
221221
# called once per each test function
@@ -456,7 +456,7 @@ def get_data_param(self):
456456
"datatype": List(Utf8),
457457
"data": self.sample_array_data,
458458
},
459-
],
459+
]
460460
}
461461

462462
@pytest.mark.parametrize("check_fn", [pa.Check.not_equal_to, pa.Check.ne])

tests/polars/test_polars_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_column_schema_regex(column_kwargs):
6565
invalid_data.pipe(schema.validate).collect()
6666

6767

68-
def test_get_columnd_backend():
68+
def test_get_column_backend():
6969
assert isinstance(pa.Column.get_backend(pl.LazyFrame()), ColumnBackend)
7070
assert isinstance(
7171
pa.Column.get_backend(check_type=pl.LazyFrame), ColumnBackend

0 commit comments

Comments
 (0)