Skip to content

Commit a3445db

Browse files
fangqclaude
andcommitted
[bug] jtypes: a polars Categorical column hung the encoder (polars 1.32+)
From polars 1.32 a Categorical's dtype.categories is a global registry whose __getitem__ answers every index, so list() of it never ended (the Python 3.9 CI job hung). Only an Enum has a fixed category list, taken with to_list(); a Categorical's keys come from its values, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 54d218f commit a3445db

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎jdata/jtypes.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,10 @@ def _polars_table(df):
514514
# the codes from the values: polars has changed how it exposes its categories;
515515
# an Enum keeps its fixed category order, a Categorical the order of appearance
516516
vals = s.cast(str).to_list()
517-
fixed = getattr(s.dtype, "categories", None)
518-
fixed = list(fixed) if fixed is not None else []
517+
# (only an Enum has a fixed list, a Series; a Categorical's .categories is, from
518+
# polars 1.32, a registry whose __getitem__ answers every index: list() never ends)
519+
fixed = getattr(s.dtype, "categories", None) if dt.startswith("Enum") else None
520+
fixed = fixed.to_list() if hasattr(fixed, "to_list") else []
519521
keys = OrderedDict((k, i) for i, k in enumerate(fixed))
520522
codes = [-1 if v is None else keys.setdefault(v, len(keys)) for v in vals]
521523
cols.append(_enum(list(keys), np.array(codes, dtype=np.int64)))

0 commit comments

Comments
 (0)