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

max_horizontal Gets Wrong Value For Decimal Columns With Different Scales #16296

Open
2 tasks done
Purpl3Koala opened this issue May 17, 2024 · 0 comments
Open
2 tasks done
Labels
A-dtype-decimal Area: decimal data type bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@Purpl3Koala
Copy link

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
import polars as pl

df = pl.DataFrame({
    'a': [25, 30, 35],
})

df = df.with_columns(
    pl.lit(str(Decimal('1.000000000001'))).cast(pl.Decimal).alias('b'),
    pl.lit(str(Decimal('3.3333333'))).cast(pl.Decimal).alias('c'),
    pl.lit(str(Decimal('2.2222222'))).cast(pl.Decimal).alias('d')
)

df = df.with_columns(
    pl.max_horizontal('b', 'c').alias('max_horizontal1'),
    pl.max_horizontal('c', 'd').alias('max_horizontal2')
)

print(df)

Log output

No response

Issue description

Creating a column with max_horizontal() across two decimal columns with different scales has a result with the wrong scale.
Max_horizontal between two decimal columns with the same scale has the expected result.

image
My apologies if I have confused scale vs precision here.

Expected behavior

Max_horizontal() outputs a column with the correct maximum value with the appropriate scale.

Installed versions

--------Version info---------
Polars:               0.20.26
Index type:           UInt32
Platform:             Windows-10-10.0.19044-SP0
Python:               3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager:  0.11.0
cloudpickle:          3.0.0
connectorx:           0.3.2
deltalake:            0.17.1
fastexcel:            0.10.4
fsspec:               2023.12.2
gevent:               24.2.1
hvplot:               0.9.2
matplotlib:           <not installed>
nest_asyncio:         1.6.0
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.2
pyarrow:              16.0.0
pydantic:             2.7.1
pyiceberg:            0.6.0
pyxlsb:               <not installed>
sqlalchemy:           2.0.29
torch:                <not installed>
xlsx2csv:             0.8.2
xlsxwriter:           3.2.0
@Purpl3Koala Purpl3Koala added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels May 17, 2024
@stinodego stinodego added the A-dtype-decimal Area: decimal data type label May 17, 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 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

2 participants