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

Unexpected results comparing booleans to strings #16139

Open
2 tasks done
etrotta opened this issue May 9, 2024 · 0 comments
Open
2 tasks done

Unexpected results comparing booleans to strings #16139

etrotta opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working P-medium Priority: medium python Related to Python Polars

Comments

@etrotta
Copy link

etrotta commented May 9, 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

>>> pl.select(pl.lit(True) == '1')
shape: (1, 1)
┌─────────┐
│ literal │
│ ---     │
│ bool    │
╞═════════╡
│ true    │
└─────────┘

>>> pl.select(pl.lit(True) == '2')
shape: (1, 1)
┌─────────┐
│ literal │
│ ---     │
│ bool    │
╞═════════╡
│ false   │
└─────────┘

>>> pl.select(pl.lit(True) == 'foo')
shape: (1, 1)
┌─────────┐
│ literal │
│ ---     │
│ bool    │
╞═════════╡
│ false   │
└─────────┘

Log output

No response

Issue description

According to users in the Discord, "we are too eager to upcast things".

Expected behavior

Expected for it to give an error, the same way it would for integers x strings

>>> pl.select(pl.lit(1) == '1')
Traceback (most recent call last):
    [....]
polars.exceptions.ComputeError: cannot compare string with numeric type (i32)

Installed versions

--------Version info---------
Polars:               0.20.25
Index type:           UInt32
Platform:             Windows-11-10.0.22631-SP0
Python:               3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            0.9.0
fsspec:               <not installed>
gevent:               <not installed>
hvplot:               <not installed>
matplotlib:           3.8.2
nest_asyncio:         <not installed>
numpy:                1.26.1
openpyxl:             3.1.2
pandas:               2.1.2
pyarrow:              15.0.0
pydantic:             2.5.2
pyiceberg:            <not installed>
pyxlsb:               <not installed>
sqlalchemy:           2.0.29
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@etrotta etrotta added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels May 9, 2024
@ritchie46 ritchie46 added P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium Priority: medium python Related to Python Polars
Projects
Status: Ready
Development

No branches or pull requests

2 participants