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

str.slice() does not respect codepoints for negative offsets #15136

Closed
2 tasks done
mcrumiller opened this issue Mar 18, 2024 · 0 comments · Fixed by #15140
Closed
2 tasks done

str.slice() does not respect codepoints for negative offsets #15136

mcrumiller opened this issue Mar 18, 2024 · 0 comments · Fixed by #15140
Assignees
Labels
accepted Ready for implementation bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@mcrumiller
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

s = pl.Series("你好世界")
s.str.n_chars()    # 4
s.str.len_bytes()  # 12 (3 bytes each)

# positive n
s.str.slice(1)   # "好世界"  - ok
s.str.slice(2)   #   "世界"  - ok
s.str.slice(3)   #     "界"  - ok
s.str.slice(4)   #       ""  - ok

# negative n
s.str.slice(-1)  #       ""  - incorrect
s.str.slice(-2)  #       ""  - incorrect
s.str.slice(-3)  #  "好世界"  - ok
s.str.slice(-4)  # "你好世界" - ok

Log output

No response

Issue description

When str.slice is provided negative indices, it does not properly extract the last n code points.

Expected behavior

s.str.slice(-1)  # "界"
s.str.slice(-2)  # "世界"

Installed versions

main

@mcrumiller mcrumiller added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Mar 18, 2024
@c-peters c-peters added the accepted Ready for implementation label Mar 25, 2024
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 needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants