Skip to content

Commit

Permalink
old polars
Browse files Browse the repository at this point in the history
  • Loading branch information
FBruzzesi committed Oct 7, 2024
1 parent f5812e4 commit f0777c6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion narwhals/_pandas_like/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ def to_dummies(
prefix=name,
prefix_sep=separator,
drop_first=drop_first,
dummy_na=has_nulls, # Adds a null column at the end, even if there aren't any.
# Adds a null column at the end, depending on whether or not there are any.
dummy_na=has_nulls,
dtype=int,
)
if has_nulls:
Expand Down
7 changes: 6 additions & 1 deletion narwhals/_polars/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,13 @@ def to_dummies(
from narwhals._polars.dataframe import PolarsDataFrame

if self._backend_version < (0, 20, 15): # pragma: no cover
has_nulls = self._native_series.is_null().any()
result = self._native_series.to_dummies(separator=separator)
result = result.select(result.columns[int(drop_first) :])
output_columns = result.columns
if drop_first:
_ = output_columns.pop(int(has_nulls))

result = result.select(output_columns)
else:
result = self._native_series.to_dummies(
separator=separator, drop_first=drop_first
Expand Down

0 comments on commit f0777c6

Please sign in to comment.