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

Handling of large integer literals is wrong when combining integers of different types/dynamic integers #20829

Open
2 tasks done
itamarst opened this issue Jan 21, 2025 · 0 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@itamarst
Copy link
Contributor

itamarst commented Jan 21, 2025

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

import pytest

import polars as pl
 
from tests.unit.conftest import INTEGER_DTYPES
 
@pytest.mark.parametrize("int_dtype", INTEGER_DTYPES)
def test_literal_integer_addition(int_dtype: pl.DataType) -> None:
    one = pl.lit(1, dtype=int_dtype)
    for i in range(100):
        value = 2**i
        assert pl.select(pl.lit(value, dtype=pl.Int128) + one).item() == value + 1
        assert pl.select(pl.lit(-value, dtype=pl.Int128) + one).item() == -value + 1
        assert pl.select(pl.lit(value) + one).item() == value + 1
        assert pl.select(pl.lit(-value) + one).item() == -value + 1

Log output

The test fails, because select(...).item() often turns into None.

Issue description

This is a continuation of the issue I discovered when diagnosing #20807.

If you look through the logic in polars-core/src/utils/supertype.rs, it hasn't been updated for Int128. One part is covered in #20830, but this is a broader issue.

Things that need fixing include (but are likely not limited to):

  • materialize_smallest_dyn_int()
  • materialize_dyn_int_pos()
  • most significantly, their caller get_supertype_with_options()

None of them acknowledge the existence of Int128 dtype, and therefore give unexpected results for large integers.

Expected behavior

See the assertions in the test.

Installed versions

Polars git as of Jan 20, 2024.
@itamarst itamarst added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jan 21, 2025
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