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

pl.lit(1) is type Int32 but pl.lit([1]) is type Int64 #13114

Open
2 tasks done
cmdlineluser opened this issue Dec 19, 2023 · 1 comment
Open
2 tasks done

pl.lit(1) is type Int32 but pl.lit([1]) is type Int64 #13114

cmdlineluser opened this issue Dec 19, 2023 · 1 comment
Labels
A-input-parsing Area: parsing input arguments bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@cmdlineluser
Copy link
Contributor

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

pl.select(a = 1)
# shape: (1, 1)
# ┌─────┐
# │ a   │
# │ --- │
# │ i32 │
# ╞═════╡
# │ 1   │
# └─────┘

Log output

No response

Issue description

list types default to Int64 which is documented as the expected type.

It seems like the non-list version should be Int64 also?

pl.select(a = [1])
# shape: (1, 1)
# ┌───────────┐
# │ a         │
# │ ---       │
# │ list[i64] │
# ╞═══════════╡
# │ [1]       │
# └───────────┘

Expected behavior

dtype of Int64?

Installed versions

--------Version info---------
Polars:               0.20.1
Index type:           UInt32
Platform:             macOS-13.6.1-arm64-arm-64bit
Python:               3.11.6 (main, Nov  2 2023, 04:39:40) [Clang 14.0.0 (clang-1400.0.29.202)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           0.3.2
deltalake:            <not installed>
fsspec:               2023.6.0
gevent:               <not installed>
matplotlib:           3.8.2
numpy:                1.26.2
openpyxl:             <not installed>
pandas:               2.0.3
pyarrow:              12.0.1
pydantic:             2.5.2
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           <not installed>
xlsx2csv:             0.8.1
xlsxwriter:           3.1.9
@cmdlineluser cmdlineluser added bug Something isn't working python Related to Python Polars labels Dec 19, 2023
@stinodego
Copy link
Member

This is an optimization. The return type of lit depends on the input. For integers, the logic is as follows:

  • If it fits in Int32, it's Int32
  • Else if it fits in Int64, it's Int64
  • Else it's UInt64

You could argue similar logic should apply to nested integers as well. I'm not 100% convinced.

@stinodego stinodego added the needs triage Awaiting prioritization by a maintainer label Jan 13, 2024
@stinodego stinodego added P-low Priority: low and removed needs triage Awaiting prioritization by a maintainer labels Jan 24, 2024
@stinodego stinodego added the A-input-parsing Area: parsing input arguments label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-input-parsing Area: parsing input arguments bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
Status: Ready
Development

No branches or pull requests

2 participants