Skip to content

Commit

Permalink
feat: add __slots__ to parameter-less dtype classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Object905 authored and stinodego committed Feb 15, 2024
1 parent 9242657 commit aa8e5c5
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def is_nested(self) -> bool: # noqa: D102
class DataType(metaclass=DataTypeClass):
"""Base class for all Polars data types."""

__slots__ = ()

def __reduce__(self) -> Any:
return (_custom_reconstruct, (type(self), object, None), self.__dict__)

Expand Down Expand Up @@ -267,70 +269,104 @@ def __contains__(self, item: Any) -> bool:
class NumericType(DataType):
"""Base class for numeric data types."""

__slots__ = ()


class IntegerType(NumericType):
"""Base class for integer data types."""

__slots__ = ()


class SignedIntegerType(IntegerType):
"""Base class for signed integer data types."""

__slots__ = ()


class UnsignedIntegerType(IntegerType):
"""Base class for unsigned integer data types."""

__slots__ = ()


class FloatType(NumericType):
"""Base class for float data types."""

__slots__ = ()


class TemporalType(DataType):
"""Base class for temporal data types."""

__slots__ = ()


class NestedType(DataType):
"""Base class for nested data types."""

__slots__ = ()


class Int8(SignedIntegerType):
"""8-bit signed integer type."""

__slots__ = ()


class Int16(SignedIntegerType):
"""16-bit signed integer type."""

__slots__ = ()


class Int32(SignedIntegerType):
"""32-bit signed integer type."""

__slots__ = ()


class Int64(SignedIntegerType):
"""64-bit signed integer type."""

__slots__ = ()


class UInt8(UnsignedIntegerType):
"""8-bit unsigned integer type."""

__slots__ = ()


class UInt16(UnsignedIntegerType):
"""16-bit unsigned integer type."""

__slots__ = ()


class UInt32(UnsignedIntegerType):
"""32-bit unsigned integer type."""

__slots__ = ()


class UInt64(UnsignedIntegerType):
"""64-bit unsigned integer type."""

__slots__ = ()


class Float32(FloatType):
"""32-bit floating point type."""

__slots__ = ()


class Float64(FloatType):
"""64-bit floating point type."""

__slots__ = ()


class Decimal(NumericType):
"""
Expand All @@ -342,6 +378,8 @@ class Decimal(NumericType):
It may be changed at any point without it being considered a breaking change.
"""

__slots__ = ("precision", "scale")

precision: int | None
scale: int

Expand Down Expand Up @@ -383,10 +421,14 @@ def __hash__(self) -> int:
class Boolean(DataType):
"""Boolean type."""

__slots__ = ()


class String(DataType):
"""UTF-8 encoded string type."""

__slots__ = ()


# Allow Utf8 as an alias for String
Utf8 = String
Expand All @@ -395,14 +437,20 @@ class String(DataType):
class Binary(DataType):
"""Binary type."""

__slots__ = ()


class Date(TemporalType):
"""Calendar date type."""

__slots__ = ()


class Time(TemporalType):
"""Time of day type."""

__slots__ = ()


class Datetime(TemporalType):
"""Calendar date and time type."""
Expand Down Expand Up @@ -606,14 +654,20 @@ def __repr__(self) -> str:
class Object(DataType):
"""Type for wrapping arbitrary Python objects."""

__slots__ = ()


class Null(DataType):
"""Type representing Null / None values."""

__slots__ = ()


class Unknown(DataType):
"""Type representing Datatype values that could not be determined statically."""

__slots__ = ()


class List(NestedType):
"""Variable length list type."""
Expand Down Expand Up @@ -738,6 +792,10 @@ def __repr__(self) -> str:
class Field:
"""Definition of a single field within a `Struct` DataType."""

__slots__ = ("name", "dtype")
name: str
dtype: PolarsDataType

def __init__(self, name: str, dtype: PolarsDataType):
"""
Definition of a single field within a `Struct` DataType.
Expand Down Expand Up @@ -766,6 +824,7 @@ def __repr__(self) -> str:
class Struct(NestedType):
"""Struct composite type."""

__slots__ = ("fields",)
fields: list[Field]

def __init__(self, fields: Sequence[Field] | SchemaDict):
Expand Down

0 comments on commit aa8e5c5

Please sign in to comment.