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

projection_pushdown regression/error from >= 0.14.15 (changes types, causes SchemaMismatch Error) #5086

Closed
2 tasks done
alexander-beedie opened this issue Oct 3, 2022 · 0 comments · Fixed by #5090
Closed
2 tasks done
Labels
bug Something isn't working python Related to Python Polars

Comments

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Oct 3, 2022

Polars version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of Polars.

Issue description

Projection pushdown can unexpectedly change types/values.
The below example succeeds in 0.14.14, but raises an exception in all versions since.

Reproducible example

Setup:

import polars as pl
a, b, c = map( pl.col, 'abc' )

x = pl.DataFrame(
    data = [
        ('a', 1, 0),
        ('a', 0, 1),
        ('a', 1, 2),
        ('b', 0, 0),
    ],
    columns = ['a','b','c'],
).lazy()

y = x.select( [a, b.take(c).cumsum().over(a) > 0] )
z = y.select( [a, (b ^ b.shift(1).over(a)).fill_null(True).alias('keep')] )

Error: (with/without projection_pushdown)

print( z.collect(projection_pushdown=False) )
# ┌─────┬───────┐
# │ a   ┆ keep  │
# │ --- ┆ ---   │
# │ str ┆ bool  │
# ╞═════╪═══════╡
# │ a   ┆ true  │
# │ a   ┆ false │
# │ a   ┆ false │
# │ b   ┆ true  │
# └─────┴───────┘

print( z.collect(projection_pushdown=True) )
# ┌─────┬──────┐
# │ a   ┆ keep │
# │ --- ┆ ---  │
# │ str ┆ i64  │
# ╞═════╪══════╡
# │ a   ┆ 1    │
# │ a   ┆ 1    │
# │ a   ┆ 1    │
# │ b   ┆ 1    │
# └─────┴──────┘

z.filter( pl.col('keep') ).collect()
# ComputeError: Filter predicate must be of type Boolean,
#  got: SchemaMisMatch(Owned("Series of dtype: Int64 != Boolean"))

Expected behavior

Projection pushdown shouldn't result in incorrect types/values.
Expected result:

# ┌─────┬──────┐
# │ a   ┆ keep │
# │ --- ┆ ---  │
# │ str ┆ bool │
# ╞═════╪══════╡
# │ a   ┆ true │
# │ b   ┆ true │
# └─────┴──────┘

Installed versions

---Version info---
Polars: 0.14.17
Index type: UInt32
Platform: macOS-12.6-arm64-arm-64bit
Python: 3.9.7 (default, Aug 12 2022, 09:02:06) 
[Clang 13.1.6 (clang-1316.0.21.2.5)]

---Optional dependencies---
pyarrow: 9.0.0
pandas: 1.4.4
numpy: 1.23.3
fsspec: 2022.7.1
connectorx: 0.3.0
xlsx2csv: <not installed>
matplotlib: 3.5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant