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

refactor(python): InterchangeDataFrame.version should be a ClassVar (not a property) #16312

Merged
merged 3 commits into from
May 19, 2024

Conversation

twoertwein
Copy link
Contributor

No description provided.

…int`) to be consistent with `InterchangeDataFrame`
@github-actions github-actions bot added internal An internal refactor or improvement python Related to Python Polars labels May 18, 2024
Copy link

codecov bot commented May 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.33%. Comparing base (27de0d8) to head (f927b46).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16312    +/-   ##
========================================
  Coverage   81.33%   81.33%            
========================================
  Files        1403     1403            
  Lines      183293   183463   +170     
  Branches     2924     2929     +5     
========================================
+ Hits       149085   149226   +141     
- Misses      33705    33734    +29     
  Partials      503      503            

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

@stinodego
Copy link
Member

stinodego commented May 19, 2024

On the Protocol it needs to be a @property since it's not instantiated. On PolarsDataFrame it can just be a regular property.

In fact, in the official reference it's a regular property, so we should follow that as closely as possible:
https://data-apis.org/dataframe-protocol/latest/API.html

If there is something not working correctly, please make an issue to discuss and I may reopen this.

@stinodego stinodego closed this May 19, 2024
@twoertwein twoertwein changed the title refactor(python): PolarsDataFrame.version is a property (not an int) to be consistent with InterchangeDataFrame refactor(python): InterchangeDataFrame.version should be a ClassVar (not a property) May 19, 2024
@twoertwein
Copy link
Contributor Author

twoertwein commented May 19, 2024

On the Protocol it needs to be a @property since it's not instantiated.

I'm sorry, I don't understand how property vs ClassVar is affected by it being instantiated or not. The ClassVar approach could be used in the protocol and based on your reference to https://data-apis.org/dataframe-protocol/latest/API.html it should be! I updated the PR with that change.

The issue is that replacing a property with a ClassVar (or the other way round), is not the same from a typing perspective. A ClassVar can be accessed on the class itself, a property can't. A ClassVar can be set, a property without a setter can't.

Mypy does not enforce this consistency unless the parent class explicitly declares the attribute as a ClassVar (pyright flags it always).

edit: since github does not render new commits for closed PRs, here is how the ClassVar version would look like:
twoertwein@6443593#diff-8f55094cafe51841709ae47ec54b72d97f52ce5ee386a6534256ad22d89abd2bR192

@stinodego stinodego reopened this May 19, 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.

You're right, ClassVar is the way to go here. Thanks for the PR and the explanation!

@stinodego stinodego merged commit fa6b1ca into pola-rs:main May 19, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal An internal refactor or improvement python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants