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

list arithmetic output dtype solely dependent on the first operand #19010

Closed
2 tasks done
jackaixin opened this issue Sep 29, 2024 · 0 comments · Fixed by #19162
Closed
2 tasks done

list arithmetic output dtype solely dependent on the first operand #19010

jackaixin opened this issue Sep 29, 2024 · 0 comments · Fixed by #19162
Assignees
Labels
A-arithmetic Area: arithmetic A-dtype-list/array Area: list/array data type accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@jackaixin
Copy link

jackaixin commented Sep 29, 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

df1 = pl.DataFrame({
    'i': [1, 2, 3],
    'b': [True, True, False],
    'f': [1., 2., 3.]
})

df1.with_columns(
    (pl.col('i') + pl.col('b')).alias('i+b'),
    (pl.col('i') + pl.col('f')).alias('i+f'),
    (pl.col('b') + pl.col('i')).alias('b+i'),
    (pl.col('b') + pl.col('f')).alias('b+f'),
    (pl.col('f') + pl.col('i')).alias('f+i'),
    (pl.col('f') + pl.col('b')).alias('f+b'),
)

df2 = pl.DataFrame({
    'i': [[1, 2, 3]],
    'b': [[True, True, False]],
    'f': [[1., 2., 3.]],
})

df2.with_columns(
    (pl.col('i') + pl.col('b')).alias('i+b'),
    (pl.col('i') + pl.col('f')).alias('i+f'),
    (pl.col('f') + pl.col('b')).alias('f+b'),
    (pl.col('f') + pl.col('i')).alias('f+i'),
)

try:
    df2.with_columns(
        (pl.col('b') + pl.col('i')).alias('b+i'),
    )
except pl.exceptions.PanicException as e:
    print(e)

try:
    df2.with_columns(
        (pl.col('b') + pl.col('f')).alias('b+f'),
    )
except pl.exceptions.PanicException as e:
    print(e)

Log output

No response

Issue description

In df1 where we do regular arithmetic, we see that the output dtypes are supertypes of both operands.

  • bool + int -> int
  • bool + float -> float
  • int + bool -> int
  • int + float -> float
  • float + bool -> float
  • float + int -> float

However, in the list arithmetic operations for df2, we see that

  • list[int] + list[bool] -> list[int] (expected)
  • list[int] + list[float] -> list[int] (unexpected)
  • list[float] + list[bool] -> list[float] (expected)
  • list[float] + list[int] -> list[float] (expected)
  • list[bool] + list[int] -> PanicException
  • list[bool] + list[float] -> PanicException

Expected behavior

  • list[int] + list[bool] -> list[int]
  • list[int] + list[float] -> list[float]
  • list[float] + list[bool] -> list[float]
  • list[float] + list[int] -> list[float]
  • list[bool] + list[int] -> list[int]
  • list[bool] + list[float] -> list[float]

Installed versions

--------Version info---------
Polars:              1.8.2
Index type:          UInt32
Platform:            macOS-15.0-arm64-arm-64bit
Python:              3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)]

----Optional dependencies----
adbc_driver_manager  1.2.0
altair               5.4.1
cloudpickle          3.0.0
connectorx           0.3.3
deltalake            0.20.1
fastexcel            0.11.6
fsspec               2024.9.0
gevent               24.2.1
great_tables         0.12.0
matplotlib           3.8.2
nest_asyncio         1.6.0
numpy                1.26.2
openpyxl             3.1.5
pandas               2.1.4
pyarrow              17.0.0
pydantic             2.9.2
pyiceberg            0.7.1
sqlalchemy           2.0.35
torch                <not installed>
xlsx2csv             0.8.3
xlsxwriter           3.2.0
@jackaixin jackaixin added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Sep 29, 2024
@nameexhaustion nameexhaustion self-assigned this Oct 5, 2024
@nameexhaustion nameexhaustion added accepted Ready for implementation P-medium Priority: medium A-dtype-list/array Area: list/array data type A-arithmetic Area: arithmetic and removed needs triage Awaiting prioritization by a maintainer labels Oct 5, 2024
@github-project-automation github-project-automation bot moved this to Ready in Backlog Oct 5, 2024
@github-project-automation github-project-automation bot moved this from Ready to Done in Backlog Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-arithmetic Area: arithmetic A-dtype-list/array Area: list/array 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.

2 participants