Skip to content

Commit

Permalink
refactor(python): Rename IntegralType to IntegerType (pola-rs#11773)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego authored Oct 16, 2023
1 parent 5d48cc8 commit befe308
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
4 changes: 2 additions & 2 deletions py-polars/polars/datatypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Int16,
Int32,
Int64,
IntegralType,
IntegerType,
List,
Null,
NumericType,
Expand Down Expand Up @@ -93,7 +93,7 @@
"Int32",
"Int64",
"Int8",
"IntegralType",
"IntegerType",
"List",
"Null",
"NumericType",
Expand Down
53 changes: 26 additions & 27 deletions py-polars/polars/datatypes/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,23 @@ def __repr__(cls) -> str:
def _string_repr(cls) -> str:
return _dtype_str_repr(cls)

def base_type(cls) -> DataTypeClass:
"""Return the base type."""
return cls
# Methods below defined here in signature only to satisfy mypy

@classproperty
def is_nested(self) -> bool:
"""Check if this data type is nested."""
return False
@classmethod
def base_type(cls) -> DataTypeClass: # noqa: D102
...

@classmethod
def is_(cls, other: PolarsDataType) -> bool:
"""Check if this DataType is the same as another DataType."""
return cls == other and hash(cls) == hash(other)
def is_(cls, other: PolarsDataType) -> bool: # noqa: D102
...

@classmethod
def is_not(cls, other: PolarsDataType) -> bool:
"""Check if this DataType is NOT the same as another DataType."""
return not cls.is_(other)
def is_not(cls, other: PolarsDataType) -> bool: # noqa: D102
...

@classproperty
def is_nested(self) -> bool: # noqa: D102
...


class DataType(metaclass=DataTypeClass):
Expand Down Expand Up @@ -97,11 +96,6 @@ def base_type(cls) -> DataTypeClass:
"""
return cls

@classproperty
def is_nested(self) -> bool:
"""Check if this data type is nested."""
return False

@classinstmethod # type: ignore[arg-type]
def is_(self, other: PolarsDataType) -> bool:
"""
Expand Down Expand Up @@ -148,6 +142,11 @@ def is_not(self, other: PolarsDataType) -> bool:
"""
return not self.is_(other)

@classproperty
def is_nested(self) -> bool:
"""Check if this data type is nested."""
return False


def _custom_reconstruct(
cls: type[Any], base: type[Any], state: Any
Expand Down Expand Up @@ -200,7 +199,7 @@ class NumericType(DataType):
"""Base class for numeric data types."""


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


Expand All @@ -225,35 +224,35 @@ def is_nested(self) -> bool:
return True


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


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


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


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


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


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


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


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


Expand Down
4 changes: 2 additions & 2 deletions py-polars/polars/type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import sys

from polars import DataFrame, Expr, LazyFrame, Series
from polars.datatypes import DataType, DataTypeClass, IntegralType, TemporalType
from polars.datatypes import DataType, DataTypeClass, IntegerType, TemporalType
from polars.dependencies import numpy as np
from polars.dependencies import pandas as pd
from polars.dependencies import pyarrow as pa
Expand All @@ -36,7 +36,7 @@
# Data types
PolarsDataType: TypeAlias = Union["DataTypeClass", "DataType"]
PolarsTemporalType: TypeAlias = Union[Type["TemporalType"], "TemporalType"]
PolarsIntegerType: TypeAlias = Union[Type["IntegralType"], "IntegralType"]
PolarsIntegerType: TypeAlias = Union[Type["IntegerType"], "IntegerType"]
OneOrMoreDataTypes: TypeAlias = Union[PolarsDataType, Iterable[PolarsDataType]]
PythonDataType: TypeAlias = Union[
Type[int],
Expand Down

0 comments on commit befe308

Please sign in to comment.