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 instantiate pl.lit with a Decimal value #13341

Closed
2 tasks done
alexander-beedie opened this issue Dec 31, 2023 · 2 comments · Fixed by #16950
Closed
2 tasks done

Cannot instantiate pl.lit with a Decimal value #13341

alexander-beedie opened this issue Dec 31, 2023 · 2 comments · Fixed by #16950
Assignees
Labels
A-dtype-decimal Area: decimal data type accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Dec 31, 2023

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

from decimal import Decimal as D
import polars as pl

with pl.Config( activate_decimals=True ):
    decimal_zero = pl.lit( D(0) )

Log output

Traceback (most recent call last):
  File "<ipython-input-13-ebe78b664c56>", line 1, in <module>
    pl.lit(D(0))
  File "/.../polars/py-polars/polars/functions/lit.py", line 150, in lit
    return wrap_expr(plr.lit(item, allow_object))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

TypeError: invalid literal value: '0'

Issue description

We cannot instantiate a decimal literal, irrespective of whether activate_decimals is True/False.

Expected behavior

We can create decimal Series; should also be able to create literals, so we can filter/operate on those Series, eg:

df = pl.DataFrame({
    "dec": [
        D("1.6666666666666666666"), 
        D("2.123456789"),
    ],
})

df.filter( dec=D("1.6666666666666666666") )

This filter should succeed; instead we get...

# TypeError: invalid literal value: '1.6666666666666666666'

Note that if we try and filter with an equivalent float it will fail to match, as the target decimal value cannot be exactly represented (the closest float is given as "1.66666666666666674068...")

Installed versions

--------Version info---------
Polars:               0.20.3-rc.2
Index type:           UInt32
Platform:             macOS-14.2.1-arm64-arm-64bit
Python:               3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)]
----Optional dependencies----
adbc_driver_manager:  0.8.0
cloudpickle:          3.0.0
connectorx:           0.3.2
deltalake:            0.14.0
fsspec:               2023.12.2
gevent:               23.9.1
matplotlib:           3.8.2
numpy:                1.26.2
openpyxl:             3.1.2
pandas:               2.1.4
pyarrow:              14.0.2
pydantic:             2.5.3
pyiceberg:            0.5.1
pyxlsb:               1.0.10
sqlalchemy:           2.0.24
xlsx2csv:             0.8.1
xlsxwriter:           3.1.9
@alexander-beedie alexander-beedie added bug Something isn't working python Related to Python Polars labels Dec 31, 2023
@deanm0000
Copy link
Collaborator

The filter fails even if I add that as a column before the filter

### this works (as you say)
df.with_columns(zz=pl.Series([D("1.6666666666666")]))
### this fails
df.with_columns(zz=pl.Series([D("1.6666666666666")])).filter(pl.col('dec')>pl.col('zz'))
PanicException: not implemented

@cgevans
Copy link
Contributor

cgevans commented Jan 8, 2024

There are two problems here:

@stinodego stinodego added the needs triage Awaiting prioritization by a maintainer label Jan 13, 2024
@alexander-beedie alexander-beedie added the A-dtype-decimal Area: decimal data type label Jan 15, 2024
@stinodego stinodego added P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels Jan 16, 2024
@stinodego stinodego self-assigned this Jun 14, 2024
@c-peters c-peters added the accepted Ready for implementation label Jun 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dtype-decimal Area: decimal data type accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants