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

index_of() with Series of length 1 and dtype Array doesn't work #21100

Open
2 tasks done
itamarst opened this issue Feb 5, 2025 · 2 comments · May be fixed by #21266
Open
2 tasks done

index_of() with Series of length 1 and dtype Array doesn't work #21100

itamarst opened this issue Feb 5, 2025 · 2 comments · May be fixed by #21266
Assignees
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 Feb 5, 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 polars as pl

dtype = pl.Array(pl.Int64(), 2)
print("Two length series works")
series = pl.Series([[1, 2], [3, 4]], dtype=dtype)
series.index_of([1, 2])

print("Two length sorted series works")
series_sorted = series.sort()
series_sorted.index_of([1, 2])

print("One length series blows up")
series = pl.Series([[1, 2]], dtype=dtype)
series.index_of([1, 2])

Log output

Two length series works
Two length sorted series works
One length series blows up
Traceback (most recent call last):
  File "/home/itamarst/devel/polars/repro.py", line 14, in <module>
    series.index_of([1, 2])
    ~~~~~~~~~~~~~~~^^^^^^^^
  File "/tmp/venv/lib/python3.13/site-packages/polars/series/series.py", line 4793, in index_of
    return F.select(F.lit(self).index_of(element)).item()
           ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.13/site-packages/polars/functions/lazy.py", line 1975, in select
    return empty_frame.select(*exprs, **named_exprs)
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.13/site-packages/polars/dataframe/frame.py", line 9413, in select
    return self.lazy().select(*exprs, **named_exprs).collect(_eager=True)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/tmp/venv/lib/python3.13/site-packages/polars/lazyframe/frame.py", line 2056, in collect
    return wrap_df(ldf.collect(callback))
                   ~~~~~~~~~~~^^^^^^^^^^
polars.exceptions.InvalidOperationError: `search_sorted` operation not supported for dtype `array[i64, 2]`

Issue description

In this one edge case, index_of() falls back to search_sorted() which then doesn't work.

Expected behavior

The example should return 0.

Installed versions

1.21 and also fairly recent git.
@itamarst itamarst added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Feb 5, 2025
@itamarst
Copy link
Contributor Author

itamarst commented Feb 5, 2025

I will fix this.

@itamarst
Copy link
Contributor Author

Starting on this now.

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

Successfully merging a pull request may close this issue.

2 participants