Skip to content

Commit 54a79f1

Browse files
fix: Make enums tolerate multiple sequence types
1 parent 8cebca6 commit 54a79f1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

dataframely/columns/enum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(
4949
alias=alias,
5050
metadata=metadata,
5151
)
52-
self.categories = categories
52+
self.categories = list(categories)
5353

5454
@property
5555
def dtype(self) -> pl.DataType:

tests/column_types/test_enum.py

+9
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,12 @@ def test_valid_cast(
5252
schema = create_schema("test", {"a": enum})
5353
df = df_type(data)
5454
assert schema.is_valid(df, cast=True) == valid
55+
56+
57+
@pytest.mark.parametrize("type1", [list, tuple])
58+
@pytest.mark.parametrize("type2", [list, tuple])
59+
def test_different_sequences(type1: type, type2: type) -> None:
60+
allowed = ["a", "b"]
61+
S = create_schema("test", {"x": dy.Enum(type1(allowed))})
62+
df = pl.DataFrame({"x": pl.Series(["a", "b"], dtype=pl.Enum(type2(allowed)))})
63+
S.validate(df)

0 commit comments

Comments
 (0)