Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't rechunk on phys_repr #17461

Merged
merged 3 commits into from
Jul 6, 2024
Merged
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
12 changes: 10 additions & 2 deletions crates/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,16 @@ impl Series {
pub fn to_physical_repr(&self) -> Cow<Series> {
use DataType::*;
match self.dtype() {
Date => Cow::Owned(self.cast(&Int32).unwrap()),
Datetime(_, _) | Duration(_) | Time => Cow::Owned(self.cast(&Int64).unwrap()),
// NOTE: Don't use cast here, as it might rechunk (if all nulls)
// which is not allowed in a phys repr.
#[cfg(feature = "dtype-date")]
Date => Cow::Owned(self.date().unwrap().0.clone().into_series()),
#[cfg(feature = "dtype-datetime")]
Datetime(_, _) => Cow::Owned(self.datetime().unwrap().0.clone().into_series()),
#[cfg(feature = "dtype-duration")]
Duration(_) => Cow::Owned(self.duration().unwrap().0.clone().into_series()),
#[cfg(feature = "dtype-time")]
Time => Cow::Owned(self.time().unwrap().0.clone().into_series()),
#[cfg(feature = "dtype-categorical")]
Categorical(_, _) | Enum(_, _) => {
let ca = self.categorical().unwrap();
Expand Down
11 changes: 11 additions & 0 deletions py-polars/tests/unit/operations/test_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,14 @@ def test_list_get_null_on_oob_true() -> None:
df = s_no_nulls.to_frame().with_columns(pl.lit(2).alias("idx"))
out = df.select(pl.col("a").list.get("idx", null_on_oob=True)).to_series()
assert_series_equal(out, expected)


def test_chunked_gather_phys_repr_17446() -> None:
dfa = pl.DataFrame({"replace_unique_id": range(2)})

for dt in [pl.Date, pl.Time, pl.Duration]:
dfb = dfa.clone()
dfb = dfb.with_columns(ds_start_date_right=pl.lit(None).cast(dt))
dfb = pl.concat([dfb, dfb])

assert dfa.join(dfb, how="left", on=pl.col("replace_unique_id")).shape == (4, 2)
Loading