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): Fix Array data type initialization #11907

Merged
merged 9 commits into from
Oct 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Array hash/repr
stinodego committed Oct 21, 2023
commit 34cfc456824784d067e4971f7c46d00bf3130698
20 changes: 10 additions & 10 deletions py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
@@ -456,18 +456,18 @@ class Unknown(DataType):


class List(NestedType):
"""Nested list/array type with variable length of inner lists."""
"""Variable length list type."""

inner: PolarsDataType | None = None

def __init__(self, inner: PolarsDataType | PythonDataType):
"""
Nested list/array type with variable length of inner lists.
Variable length list type.
Parameters
----------
inner
The `DataType` of values within the list
The ``DataType`` of the values within each list.
Examples
--------
@@ -518,26 +518,26 @@ def __repr__(self) -> str:


class Array(NestedType):
"""Nested list/array type with fixed length of inner arrays."""
"""Fixed length list type."""

inner: PolarsDataType | None = None
width: int

def __init__(self, width: int, inner: PolarsDataType | PythonDataType = Null):
"""
Nested list/array type with fixed length of inner arrays.
Fixed length list type.
Parameters
----------
width
The fixed size length of the inner arrays.
The length of the arrays.
inner
The `DataType` of values within the inner arrays
The ``DataType`` of the values within each array.
Examples
--------
>>> s = pl.Series(
... "a", [[1, 2], [4, 3]], dtype=pl.Array(width=2, inner=pl.Int64)
... "a", [[1, 2], [4, 3]], dtype=pl.Array(inner=pl.Int64, width=2)
... )
>>> s
shape: (2,)
@@ -570,11 +570,11 @@ def __eq__(self, other: PolarsDataType) -> bool: # type: ignore[override]
return False

def __hash__(self) -> int:
return hash((self.__class__, self.inner))
return hash((self.__class__, self.inner, self.width))

def __repr__(self) -> str:
class_name = self.__class__.__name__
return f"{class_name}({self.inner!r})"
return f"{class_name}({self.inner!r}, {self.width})"


class Field: