Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

search_sorted silently allows comparisons between different types #18096

Closed
2 tasks done
cmdlineluser opened this issue Aug 8, 2024 · 2 comments · Fixed by #18143
Closed
2 tasks done

search_sorted silently allows comparisons between different types #18096

cmdlineluser opened this issue Aug 8, 2024 · 2 comments · Fixed by #18143
Assignees
Labels
accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars regression Issue introduced by a new release

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

df = pl.DataFrame({
    "foo": [1, 4, 7],
    "bar": [2, 3, 5]
})

df.with_columns(idx = pl.col("foo").search_sorted("bar"))

Log output

No response

Issue description

I just noticed this as previously (it seems around <= 0.20.23) passing a string to search_sorted was parsed as a column name.

It now seems to be parsed as a literal, but there does not seem to be a type check.

So in this case, we end up getting a "valid" result from searching an int column with a string, which seems unintended?

df.with_columns(
    expected = pl.col("foo").search_sorted(pl.col("bar")),
    actual = pl.col("foo").search_sorted("bar")
)

# shape: (3, 4)
# ┌─────┬─────┬──────────┬────────┐
# │ foo ┆ bar ┆ expected ┆ actual │
# │ --- ┆ --- ┆ ---      ┆ ---    │
# │ i64 ┆ i64 ┆ u32      ┆ u32    │
# ╞═════╪═════╪══════════╪════════╡
# │ 1   ┆ 2   ┆ 1        ┆ 3      │
# │ 4   ┆ 3   ┆ 1        ┆ 3      │
# │ 7   ┆ 5   ┆ 2        ┆ 3      │
# └─────┴─────┴──────────┴────────┘

Expected behavior

SchemaError invalid dtype?

Installed versions

--------Version info---------
Polars:               1.4.1
Index type:           UInt32
Platform:             macOS-13.6.1-arm64-arm-64bit
Python:               3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]

----Optional dependencies----
adbc_driver_manager:  <not installed>
cloudpickle:          <not installed>
connectorx:           <not installed>
deltalake:            <not installed>
fastexcel:            <not installed>
fsspec:               <not installed>
gevent:               <not installed>
great_tables:         <not installed>
hvplot:               <not installed>
matplotlib:           <not installed>
nest_asyncio:         <not installed>
numpy:                1.26.4
openpyxl:             <not installed>
pandas:               2.2.1
pyarrow:              15.0.2
pydantic:             <not installed>
pyiceberg:            <not installed>
sqlalchemy:           <not installed>
torch:                <not installed>
xlsx2csv:             <not installed>
xlsxwriter:           <not installed>
@cmdlineluser cmdlineluser added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Aug 8, 2024
@deanm0000
Copy link
Collaborator

deanm0000 commented Aug 8, 2024

I don't know if that was a lucky guess or you're being coy with "seems around" but 0.20.23 is exactly the first version where that behavior changed/broke.

Here's the PR
7ae1e58

@deanm0000 deanm0000 added regression Issue introduced by a new release P-medium Priority: medium and removed needs triage Awaiting prioritization by a maintainer labels Aug 8, 2024
@ritchie46
Copy link
Member

Ouch.. that's a sneaky one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working P-medium Priority: medium python Related to Python Polars regression Issue introduced by a new release
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants