Skip to content

Commit

Permalink
fix: Ensure sorted flag is unset after Int->String cast (#19470)
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion authored Oct 27, 2024
1 parent e7a84bc commit b222796
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crates/polars-core/src/chunked_array/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ where
// - remain signed
// - unsigned -> signed
// this may still fail with overflow?
let dtype = self.dtype();

let to_signed = dtype.is_signed_integer();
let unsigned2unsigned = dtype.is_unsigned_integer() && dtype.is_unsigned_integer();
let unsigned2unsigned =
self.dtype().is_unsigned_integer() && dtype.is_unsigned_integer();
let allowed = to_signed || unsigned2unsigned;

if (allowed)
Expand Down
6 changes: 6 additions & 0 deletions py-polars/tests/unit/operations/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,9 @@ def test_cast_consistency() -> None:
assert pl.DataFrame().with_columns(a=pl.lit(0.0)).with_columns(
b=pl.col("a").cast(pl.String), c=pl.lit(0.0).cast(pl.String)
).to_dict(as_series=False) == {"a": [0.0], "b": ["0.0"], "c": ["0.0"]}


def test_cast_int_to_string_unsets_sorted_flag_19424() -> None:
s = pl.Series([1, 2]).set_sorted()
assert s.flags["SORTED_ASC"]
assert not s.cast(pl.String).flags["SORTED_ASC"]

0 comments on commit b222796

Please sign in to comment.