Skip to content

Commit 07b3d09

Browse files
authored
feat: Add is_boolean method to DType. (#2935)
1 parent 992515f commit 07b3d09

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

narwhals/dtypes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def is_temporal(cls: type[Self]) -> bool:
9595
def is_nested(cls: type[Self]) -> bool:
9696
return issubclass(cls, NestedType)
9797

98+
@classmethod
99+
def is_boolean(cls: type[Self]) -> bool:
100+
return issubclass(cls, Boolean)
101+
98102
def __eq__(self, other: DType | type[DType]) -> bool: # type: ignore[override]
99103
from narwhals._utils import isinstance_or_issubclass
100104

tests/dtypes_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ def test_dtype_is_x() -> None:
315315
is_decimal = {nw.Decimal}
316316
is_temporal = {nw.Datetime, nw.Date, nw.Duration, nw.Time}
317317
is_nested = {nw.Array, nw.List, nw.Struct}
318+
is_boolean = {nw.Boolean}
318319

319320
for dtype in dtypes:
320321
assert dtype.is_numeric() == (
@@ -332,6 +333,7 @@ def test_dtype_is_x() -> None:
332333
assert dtype.is_decimal() == (dtype in is_decimal)
333334
assert dtype.is_temporal() == (dtype in is_temporal)
334335
assert dtype.is_nested() == (dtype in is_nested)
336+
assert dtype.is_boolean() == (dtype in is_boolean)
335337

336338

337339
@pytest.mark.skipif(POLARS_VERSION < (1, 18), reason="too old for Int128")

0 commit comments

Comments
 (0)