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

feat(python)!: Properly apply strict parameter in Series constructor #16939

Merged
merged 10 commits into from
Jun 15, 2024

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented Jun 13, 2024

Closes #14427

The behavior of the Series constructor has been updated.
Generally, it will be more strict, unless the user passes strict=False.

Strict construction is more efficient than non-strict construction, so make sure to pass values of the same data type to the constructor for the best performance.

Example

Before:

>>> s = pl.Series([1, 2, 3.5])
shape: (3,)
Series: '' [f64]
[
        1.0
        2.0
        3.5
]
>>> s = pl.Series([1, 2, 3.5], strict=False)
shape: (3,)
Series: '' [i64]
[
        1
        2
        null
]
>>> s = pl.Series([1, 2, 3.5], strict=False, dtype=pl.Int8)
Series: '' [i8]
[
        1
        2
        null
]

After:

>>> s = pl.Series([1, 2, 3.5])
Traceback (most recent call last):
...
TypeError: unexpected value while building Series of type Int64; found value of type Float64: 3.5

Hint: Try setting `strict=False` to allow passing data with mixed types.
>>> s = pl.Series([1, 2, 3.5], strict=False)
shape: (3,)
Series: '' [f64]
[
        1.0
        2.0
        3.5
]
>>> s = pl.Series([1, 2, 3.5], strict=False, dtype=pl.Int8)
Series: '' [i8]
[
        1
        2
        3
]

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Jun 13, 2024
Copy link

codecov bot commented Jun 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.04%. Comparing base (687dee3) to head (8679207).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16939      +/-   ##
==========================================
+ Coverage   81.02%   81.04%   +0.02%     
==========================================
  Files        1445     1445              
  Lines      190134   190141       +7     
  Branches     2712     2709       -3     
==========================================
+ Hits       154050   154103      +53     
+ Misses      35585    35540      -45     
+ Partials      499      498       -1     

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

Copy link

codspeed-hq bot commented Jun 14, 2024

CodSpeed Performance Report

Merging #16939 will improve performances by 19.94%

Comparing constructor-strict (8679207) with main (687dee3)

Summary

⚡ 1 improvements
✅ 36 untouched benchmarks

Benchmarks breakdown

Benchmark main constructor-strict Change
test_groupby_h2oai_q5 2.1 ms 1.7 ms +19.94%

@stinodego stinodego marked this pull request as ready for review June 14, 2024 23:11
@stinodego stinodego changed the title feat(python): Apply strictness in Series constructor feat(python)!: Properly apply strict parameter in Series constructor Jun 14, 2024
@github-actions github-actions bot added the breaking Change that breaks backwards compatibility label Jun 14, 2024
*,
strict: bool,
) -> PySeries:
"""Construct Series, with fallbacks for basic type mismatch (eg: bool/int)."""
while True:
Copy link
Member

Choose a reason for hiding this comment

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

auch

@ritchie46 ritchie46 merged commit 6b36e9b into main Jun 15, 2024
34 checks passed
@ritchie46 ritchie46 deleted the constructor-strict branch June 15, 2024 07:44
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Change that breaks backwards compatibility enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series constructor logic overhaul
2 participants