We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
Example provided as-is from a comment made in #22802 by @ctdunc.
import polars as pl class MyDf(pl.DataFrame): def has_column(self, col: str) -> bool: return col in self.columns df = pl.DataFrame( { "foo": [1, 2, 3], "ham": ["a", "b", "c"], } ) my_df = MyDf( { "foo": [1, 2, 3], "bar": [6, 7, 8], } ) # works fine df_join_mine = df.join(my_df, on="foo") # type error mine_join_df = my_df.join(df, on="foo")
The type equality check is too restrictive, as sometimes subclasses are preferred in order to modify or add certain behaviours.
Allow operations such as joins, that check for type equality, to go through, if the other argument is a subclass of self.
other
--------Version info--------- Polars: 1.30.0 Index type: UInt32 Platform: Windows-10-10.0.22631-SP0 Python: 3.11.7 (tags/v3.11.7:fa7a6f2, Dec 4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] LTS CPU: False ----Optional dependencies---- Azure CLI 'az' is not recognized as an internal or external command, operable program or batch file. <not installed> adbc_driver_manager <not installed> altair <not installed> azure.identity <not installed> boto3 <not installed> cloudpickle <not installed> connectorx <not installed> deltalake <not installed> fastexcel <not installed> fsspec <not installed> gevent <not installed> google.auth <not installed> great_tables <not installed> matplotlib <not installed> numpy <not installed> openpyxl <not installed> pandas <not installed> polars_cloud <not installed> pyarrow <not installed> pydantic <not installed> pyiceberg <not installed> sqlalchemy <not installed> torch <not installed> xlsx2csv <not installed> xlsxwriter <not installed>
The text was updated successfully, but these errors were encountered:
We don't actually support subclassing1, so this is expected/correct behaviour.
Some methods will return the subclassed type (when inheriting from DataFrame/etc), but many will not. For example, with your MyDf class/example above:
MyDf
type(my_df) # __main__.MyDf type(my_df.head(1)) # __main__.MyDf type(my_df.select("bar")) # polars.dataframe.frame.DataFrame type(my_df.filter(pl.col("bar") >= 7)) # polars.dataframe.frame.DataFrame
https://github.com/pola-rs/polars/pull/7426#issuecomment-1475834972 ↩
Sorry, something went wrong.
We don't actually support subclassing1, so this is expected/correct behaviour. Some methods will return the subclassed type (when inheriting from DataFrame/etc), but many will not. For example, with your MyDf class/example above: type(my_df) main.MyDf type(my_df.head(1)) main.MyDf type(my_df.select("bar")) polars.dataframe.frame.DataFrame type(my_df.filter(pl.col("bar") >= 7)) polars.dataframe.frame.DataFrame Footnotes feat(python): Easier subclassing #7426 (comment) ↩
type(my_df)
type(my_df.head(1))
type(my_df.select("bar"))
type(my_df.filter(pl.col("bar") >= 7))
Added a comment on the PR, let me know if instead you'd like to continue the discussion here.
Successfully merging a pull request may close this issue.
Checks
Reproducible example
Example provided as-is from a comment made in #22802 by @ctdunc.
Log output
Issue description
The type equality check is too restrictive, as sometimes subclasses are preferred in order to modify or add certain behaviours.
Expected behavior
Allow operations such as joins, that check for type equality, to go through, if the
other
argument is a subclass of self.Installed versions
The text was updated successfully, but these errors were encountered: