Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions narwhals/_plan/expressions/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ def _matches(self, dtype: IntoDType) -> bool:
class Enum(DTypeSelector, dtype=_dtypes.Enum): ...


class Decimal(DTypeSelector, dtype=_dtypes.Decimal): ...


class Float(DTypeSelector, dtype=FloatType): ...


Expand Down
6 changes: 6 additions & 0 deletions narwhals/_plan/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"by_name",
"categorical",
"datetime",
"decimal",
"duration",
"empty",
"enum",
Expand Down Expand Up @@ -231,6 +232,10 @@ def enum() -> Selector:
return s_ir.Enum().to_selector_ir().to_narwhals()


def decimal() -> Selector:
return s_ir.Decimal().to_selector_ir().to_narwhals()


def first() -> Selector:
return s_ir.ByIndex.from_index(0).to_selector_ir().to_narwhals()

Expand Down Expand Up @@ -284,4 +289,5 @@ def temporal() -> Selector:
_dtypes.Array: array,
_dtypes.List: list,
_dtypes.Struct: struct,
_dtypes.Decimal: decimal,
}
11 changes: 11 additions & 0 deletions tests/plan/selectors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,17 @@ def test_selector_struct() -> None:
df.assert_selects(~ncs.struct(), "a", "b", "d", "f", "g")


def test_selector_decimal(schema_mixed: nw.Schema) -> None:
df = Frame(schema_mixed)
df.assert_selects(ncs.decimal())
df = df.from_mapping(
{"zz0": nw.Float64(), "zz1": nw.Decimal(38, 5), "zz2": nw.Decimal()}
)
df.assert_selects(ncs.numeric(), "zz0", "zz1", "zz2")
df.assert_selects(ncs.decimal(), "zz1", "zz2")
df.assert_selects(~ncs.decimal(), "zz0")


def test_selector_matches_22816() -> None:
df = Frame.from_names("ham", "hamburger", "foo", "bar")
df.assert_selects(ncs.matches(r"^ham.*$"), "ham", "hamburger")
Expand Down
Loading