Closed datenzauberai closed 2 weeks ago
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 80.81%. Comparing base (
11fe9d8
) to head (a6e343f
).
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
While pl.List
gets first exploded and is reshaped according to the spec...
print(pl.DataFrame(pl.Series(name="a", values=[[1, 2, 3, 4]], dtype=pl.List(pl.Int64))).select(pl.col("a").reshape((2,2))))
print(pl.DataFrame(pl.Series(name="a", values=[[1], [2], [3], [4]], dtype=pl.List(pl.Int64))).select(pl.col("a").reshape((2,2))))
┌───────────┐
│ a │
│ --- │
│ list[i64] │
╞═══════════╡
│ [1, 2] │
│ [3, 4] │
└───────────┘
pl.Array
is treated differently right now more like a scalar datatype...
print(pl.DataFrame(pl.Series(name="a", values=[[1, 2, 3, 4]], dtype=pl.Array(pl.Int64, width=4))).select(pl.col("a").reshape((2, 2))))
ComputeError: cannot reshape len 1 into shape [2, 2]
print(pl.DataFrame(pl.Series(name="a", values=[[1], [2], [3], [4]], dtype=pl.Array(pl.Int64, width=1))).select(pl.col("a").reshape((2, 2))))
┌─────────────────────┐
│ a │
│ --- │
│ list[array[i64, 1]] │
╞═════════════════════╡
│ [[1], [2]] │
│ [[3], [4]] │
└─────────────────────┘
We could explode pl.Array(inner_dtype)
as well and then return pl.List(inner_dtype)
, but one could also argue that not exploding is how it should work and makes sense if one uses pl.Array
for struct-like things.
pl.Array
would even be a much more natural output type than pl.List
for this operation, but it would not be able to handle empty series (no pl.Array(width=0)
) and I guess that's too much of a change...
This is a fix for https://github.com/pola-rs/polars/issues/15543
Improvements:
dimensions < -1
will raise an error instead of panicking-1
whenever it is possible;(-1, -1)
will be inferred to either(0, 0)
for an empty series or to(len(), 1)
for a non-empty series(0, 0)
or(0, )
(after inferring)rows*cols == len()
after inferring placeholders will raise an error