Skip to content

Commit

Permalink
feat: add __slots__ to Series, DataFrame, Categorical and Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Object905 authored and stinodego committed Feb 26, 2024
1 parent 10f723f commit 7da83bd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ class DataFrame:
False
"""

__slots__ = ("_df",)
_df: PyDataFrame
_accessors: ClassVar[set[str]] = {"plot"}

def __init__(
Expand Down
4 changes: 3 additions & 1 deletion py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def _custom_reconstruct(
class DataTypeGroup(frozenset): # type: ignore[type-arg]
"""Group of data types."""

__slots__ = ("_match_base_type",)
_match_base_type: bool

def __new__(
Expand Down Expand Up @@ -379,7 +380,6 @@ class Decimal(NumericType):
"""

__slots__ = ("precision", "scale")

precision: int | None
scale: int

Expand Down Expand Up @@ -558,6 +558,7 @@ class Categorical(DataType):
or string value (lexical).
"""

__slots__ = ("ordering",)
ordering: CategoricalOrdering | None

def __init__(
Expand Down Expand Up @@ -592,6 +593,7 @@ class Enum(DataType):
It may be changed at any point without it being considered a breaking change.
"""

__slots__ = ("categories",)
categories: Series

def __init__(self, categories: Series | Iterable[str]):
Expand Down
3 changes: 2 additions & 1 deletion py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ class Series:
]
"""

_s: PySeries = None
__slots__ = ("_s",)
_s: PySeries
_accessors: ClassVar[set[str]] = {
"arr",
"cat",
Expand Down

0 comments on commit 7da83bd

Please sign in to comment.