-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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)!: Allow all DataType
objects to be instantiated
#12470
Conversation
DataType::Int8 => { | ||
let class = pl.getattr(intern!(py, "Int8")).unwrap(); | ||
class.call0().unwrap().into() | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use call0()
to instantiate the Int8
class.
@@ -413,6 +467,24 @@ impl FromPyObject<'_> for Wrap<DataType> { | |||
}, | |||
} | |||
}, | |||
"Int8" => DataType::Int8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instances of Int8
can be converted into the corresponding Rust datatype.
@@ -130,7 +130,7 @@ def test_ipc_schema(compression: IpcCompression) -> None: | |||
df.write_ipc(f, compression=compression) | |||
f.seek(0) | |||
|
|||
expected = {"a": pl.Int64, "b": pl.Utf8, "c": pl.Boolean} | |||
expected = {"a": pl.Int64(), "b": pl.Utf8(), "c": pl.Boolean()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous equality still holds - this change is just to satisfy mypy.
3f51fa0
to
ab4de0a
Compare
ab4de0a
to
1f9522a
Compare
schema
/dtype
methodsDataType
objects to be instantiated
Closes #6163
This went a lot more smoothly than I expected. This update should cause almost no friction with users.
Changes
DataType
objects, rather than a mix of classes/instances:Series.dtype
DataFrame.dtypes
LazyFrame.dtypes
DataFrame.schema
LazyFrame.schema
Series.struct.schema
Int8()
is no longer magically converted into anInt8
class.__hash__
,__eq__
, and__repr__
methods. These are valid for 'simple' data types. 'Complex' data types likeDatetime
andList
overwrite these defaults as they did before.Almost everything still works as before. The only thing really affected is the
is
operator:Before
After
>>> s.dtype is pl.Int8 False
Use the equality operator or
isinstance
instead:And users may have to update some of their type hints.
After this is merged, there can be a little more cleanup and refactoring to smooth things out further behind the scenes. But this should take care of the user-facing changes I intended to make.