Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Changelog
4.2.2 - unreleased
------------------

**Bug fixes:**

- Fixed compatibility with polars 2.0, which removed ``Series.cat.get_categories()``.

**Other changes:**

- Clarified that ``sparse_threshold`` is used to sparsify numerical columns and is not used to densify columns that are already sparse.
Expand Down
6 changes: 3 additions & 3 deletions src/tabmat/categorical_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ def _extract_codes_and_categories_pandas(cat_vec) -> tuple[np.ndarray, np.ndarra
def _extract_codes_and_categories_polars(cat_vec) -> tuple[np.ndarray, np.ndarray]:
dtype = cat_vec.dtype
if isinstance(dtype, pl.Enum):
categories = cat_vec.cat.get_categories().to_numpy()
categories = dtype.categories.to_numpy()
indices = cat_vec.to_physical().fill_null(-1).to_numpy()
return indices, categories

if not isinstance(cat_vec.dtype, pl.Categorical):
cat_vec = cat_vec.cast(pl.Categorical)
# as of polars 1.32, `get_categories()` won't yield a useful result as
# this is "not per column" anymore.
# as of polars 1.32, `Series.cat.get_categories()` won't yield a useful
# result as this is "not per column" anymore (and it is removed in 2.0).
mask = cat_vec.is_null()
categories = cat_vec.filter(~mask).unique().sort().to_numpy()
indices = np.nan_to_num(cat_vec.rank("dense").to_numpy() - 1, nan=-1)
Expand Down
Loading