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

Cannot filter on decimal fields in parquet files using is_in() #16150

Open
2 tasks done
lmocsi opened this issue May 10, 2024 · 0 comments
Open
2 tasks done

Cannot filter on decimal fields in parquet files using is_in() #16150

lmocsi opened this issue May 10, 2024 · 0 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@lmocsi
Copy link

lmocsi commented May 10, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

#create a parquet file containing decimal data type, eg:
import pandas as pd
import decimal
df = pd.DataFrame({'value': [0.0, 0.1, 0.3, 0.4, 0.5]})
df['value_decimal'] = df['value'].astype(str).map(decimal.Decimal)
df['integer'] = (df['value']*10).astype(int).map(decimal.Decimal)
df.to_parquet("test_data.parquet", index=False)

If you do a scan_parquet and then filter on it like:

import polars as pl
df = pl.scan_parquet('test_data.parquet')
df.filter(pl.col('value_decimal').is_in([0.0,0.1])).collect()

you'll get an error:
InvalidOperationError: is_in cannot check for Float64 values in Decimal(Some(1), Some(1)) data

Though you can always cast, like:
df.filter(pl.col('value_decimal').cast(pl.Float32).is_in([0.0, 0.1])).collect() # ???
which runs without errors, but fails to return value 0.1 !!!

Filtering on "integer" decimals does fail as well:
df.filter(pl.col('integer').is_in([3.0,4.0])).collect()
InvalidOperationError: is_in cannot check for Float64 values in Decimal(Some(1), Some(0)) data

Though casting here works well:
df.filter(pl.col('integer').cast(pl.Float32).is_in([3.0,4.0])).collect()

Log output

see Reproducible example

Issue description

InvalidOperationError: is_in cannot check for Float64 values in Decimal(Some(1), Some(1)) data
InvalidOperationError: is_in cannot check for Int64 values in Decimal(Some(1), Some(0)) data

Expected behavior

Does not fail, returns the correct results

Installed versions

--------Version info---------
Polars:               0.20.25
Index type:           UInt32
Platform:             Linux-4.18.0-372.76.1.el8_6.x86_64-x86_64-with-glibc2.28
Python:               3.9.13 (main, Oct 13 2022, 21:15:33) 
[GCC 11.2.0]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          2.0.0
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               2022.02.0
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           3.8.2
nest_asyncio:         1.5.5
numpy:                1.23.5
openpyxl:             3.0.9
pandas:               2.2.0
pyarrow:              15.0.2
pydantic:             <not installed>
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           1.4.27
torch:                1.10.2
xlsx2csv:             <not installed>
xlsxwriter:           3.1.9
@lmocsi lmocsi added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

1 participant