From befe30893a3e69c68b7efa5d6dc26b8bc7039146 Mon Sep 17 00:00:00 2001 From: Stijn de Gooijer Date: Tue, 17 Oct 2023 00:52:10 +0200 Subject: [PATCH] refactor(python): Rename `IntegralType` to `IntegerType` (#11773) --- py-polars/polars/datatypes/__init__.py | 4 +- py-polars/polars/datatypes/classes.py | 53 +++++++++++++------------- py-polars/polars/type_aliases.py | 4 +- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/py-polars/polars/datatypes/__init__.py b/py-polars/polars/datatypes/__init__.py index dc69e38eca39..9c5136f8d5e6 100644 --- a/py-polars/polars/datatypes/__init__.py +++ b/py-polars/polars/datatypes/__init__.py @@ -18,7 +18,7 @@ Int16, Int32, Int64, - IntegralType, + IntegerType, List, Null, NumericType, @@ -93,7 +93,7 @@ "Int32", "Int64", "Int8", - "IntegralType", + "IntegerType", "List", "Null", "NumericType", diff --git a/py-polars/polars/datatypes/classes.py b/py-polars/polars/datatypes/classes.py index 39e16d6d4ff2..0520866d76a8 100644 --- a/py-polars/polars/datatypes/classes.py +++ b/py-polars/polars/datatypes/classes.py @@ -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): @@ -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: """ @@ -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 @@ -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.""" @@ -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.""" diff --git a/py-polars/polars/type_aliases.py b/py-polars/polars/type_aliases.py index ea6764e1d2af..a1bbb246b1bc 100644 --- a/py-polars/polars/type_aliases.py +++ b/py-polars/polars/type_aliases.py @@ -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 @@ -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],