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

fix(python): Address inconsistency with use of Python types in frame-level cast #19657

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Nov 6, 2024

We supported df.cast({"col": str}) but raised an error on df.cast(str); made the behaviour for both styles of call consistent.

Also:
Bonus docstring examples for Schema methods.

Example

import polars as pl

df = pl.DataFrame({
    "colx": [100_000, 200_000, 300_000],
    "coly": [date(1999,12,31), date(2020,1,1), date(2077,7,5)],
})

Before:

df.cast(str)
# TypeError: argument 'dtype': 'type' is not a Polars data type

After:

df.cast(str) 
# shape: (3, 2)
# ┌────────┬────────────┐
# │ colx   ┆ coly       │
# │ ---    ┆ ---        │
# │ str    ┆ str        │
# ╞════════╪════════════╡
# │ 100000 ┆ 1999-12-31 │
# │ 200000 ┆ 2020-01-01 │
# │ 300000 ┆ 2077-07-05 │
# └────────┴────────────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Nov 6, 2024
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.86%. Comparing base (047e578) to head (d88600e).
Report is 21 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19657      +/-   ##
==========================================
- Coverage   79.92%   79.86%   -0.06%     
==========================================
  Files        1536     1537       +1     
  Lines      211700   211924     +224     
  Branches     2445     2446       +1     
==========================================
+ Hits       169199   169254      +55     
- Misses      41946    42116     +170     
+ Partials      555      554       -1     

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

@alexander-beedie alexander-beedie changed the title fix: Address inconsistency in use of Python types in frame-level cast fix: Address inconsistency with use of Python types in frame-level cast Nov 6, 2024
@alexander-beedie alexander-beedie changed the title fix: Address inconsistency with use of Python types in frame-level cast fix(python): Address inconsistency with use of Python types in frame-level cast Nov 6, 2024
@alexander-beedie alexander-beedie removed the rust Related to Rust Polars label Nov 6, 2024
Copy link
Member

@stinodego stinodego 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!

@stinodego stinodego merged commit 9c08893 into pola-rs:main Nov 7, 2024
16 checks passed
@alexander-beedie alexander-beedie deleted the frame-level-cast-pytypes branch November 7, 2024 15:17
tylerriccio33 pushed a commit to tylerriccio33/polars that referenced this pull request Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants