Skip to content

feat: Add dtype to str.to_integer() #22239

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

Merged
merged 22 commits into from
Jun 26, 2025
Merged

Conversation

math-hiyoko
Copy link
Contributor

@math-hiyoko math-hiyoko commented Apr 12, 2025

This adds a dtype option to str.to_integer(), limited to PolarsIntegerTypes. Each dtype corresponds to a call to the appropriate Rust from_str_radix implementation. The default type is pl.Int64.

Example

import polars as pl
df = pl.DataFrame(
    {
        "str": [
            "-6129899454972456276923959272",
            "1A44E53BFEBA967E6682FBB0",
            "10100110111110110101110100000100110010101111000100011000000100010101010101101011111111101000",
            None,
            "7798994549724957734429272",
        ],
        "base": [10, 16, 2, 8, None],
    }
)
df.select(int=pl.col("str").str.to_integer(base="base", dtype=pl.Int128))
# shape: (5, 1)
# Series: 'bin' [i32]
# ┌───────────────────────────────┐
# │ int                           │
# │ ---                           │
# │ i128                          │
# ╞═══════════════════════════════╡
# │ -6129899454972456276923959272 │
# │ 8129899739726392769273592752  │
# │ 3229899454972495776923959272  │
# │ null                          │
# │ null                          │
# └───────────────────────────────┘

close #20567

@math-hiyoko math-hiyoko marked this pull request as draft April 12, 2025 11:01
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Apr 12, 2025
Copy link

codecov bot commented Apr 12, 2025

Codecov Report

Attention: Patch coverage is 97.72727% with 2 lines in your changes missing coverage. Please review.

Project coverage is 80.71%. Comparing base (63d0b8f) to head (2712138).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
.../polars-ops/src/chunked_array/strings/namespace.rs 98.55% 1 Missing ⚠️
.../polars-python/src/lazyframe/visitor/expr_nodes.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #22239      +/-   ##
==========================================
- Coverage   80.72%   80.71%   -0.02%     
==========================================
  Files        1644     1644              
  Lines      221684   221719      +35     
  Branches     2786     2786              
==========================================
- Hits       178957   178955       -2     
- Misses      42064    42101      +37     
  Partials      663      663              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@math-hiyoko math-hiyoko marked this pull request as ready for review April 14, 2025 13:24
@math-hiyoko
Copy link
Contributor Author

Everything is ready now

@orlp
Copy link
Member

orlp commented Apr 15, 2025

Also closes #11612.

@math-hiyoko
Copy link
Contributor Author

All checks are green; happy to rebase or tweak if needed. Thanks!

@math-hiyoko
Copy link
Contributor Author

Hi @orlp – gentle ping.
All checks are green and this PR has been sitting ready for review for a few weeks.
If anything blocks merging, please let me know and I’ll address it promptly.
Thanks in advance for your time!

@math-hiyoko
Copy link
Contributor Author

Hi maintainers,

Just a gentle reminder about this PR (#22239) — it’s been open for a couple of months now, CI is all green, and I’m happy to make any further tweaks if needed. I’d really appreciate it if someone could take a look when you get a chance. Thanks a lot!

@orlp
Copy link
Member

orlp commented Jun 26, 2025

Sorry I missed your ping last week, I was on holiday. I will take a look today.

@orlp orlp self-assigned this Jun 26, 2025
Copy link
Member

@orlp orlp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :) Thanks for your contribution.

@orlp orlp merged commit b668712 into pola-rs:main Jun 26, 2025
29 checks passed
@math-hiyoko math-hiyoko deleted the feature/#20567 branch June 26, 2025 07:47
@math-hiyoko
Copy link
Contributor Author

Thank you all for taking the time to review and approve this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parse integer strings to Int128, e.g. str.to_integer(..., dtype=pl.Int128)
2 participants