Skip to content

Commit

Permalink
Run pyupgrade 2.31.0, only changes to typing.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdice committed Jan 26, 2022
1 parent e23aa5c commit 54b16b9
Show file tree
Hide file tree
Showing 23 changed files with 203 additions and 220 deletions.
2 changes: 1 addition & 1 deletion python/cudf/cudf/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def wrapped_func(obj):


def _union_categoricals(
to_union: List[Union[cudf.Series, cudf.CategoricalIndex]],
to_union: list[cudf.Series | cudf.CategoricalIndex],
sort_categories: bool = False,
ignore_order: bool = False,
):
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/_base_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BaseIndex(Serializable):
"""Base class for all cudf Index types."""

dtype: DtypeObj
_accessors: Set[Any] = set()
_accessors: set[Any] = set()
_data: ColumnAccessor

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions python/cudf/cudf/core/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Buffer(Serializable):
_owner: Any

def __init__(
self, data: Any = None, size: Optional[int] = None, owner: Any = None
self, data: Any = None, size: int | None = None, owner: Any = None
):

if isinstance(data, Buffer):
Expand Down Expand Up @@ -117,7 +117,7 @@ def _init_from_array_like(self, data, owner):
f"Cannot construct Buffer from {data.__class__.__name__}"
)

def serialize(self) -> Tuple[dict, list]:
def serialize(self) -> tuple[dict, list]:
header = {} # type: Dict[Any, Any]
header["type-serialized"] = pickle.dumps(type(self))
header["constructor-kwargs"] = {}
Expand Down
50 changes: 25 additions & 25 deletions python/cudf/cudf/core/column/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def __init__(self, parent: SeriesOrSingleColumnIndex):
super().__init__(parent=parent)

@property
def categories(self) -> "cudf.core.index.BaseIndex":
def categories(self) -> cudf.core.index.BaseIndex:
"""
The categories of this categorical.
"""
return cudf.core.index.as_index(self._column.categories)

@property
def codes(self) -> "cudf.Series":
def codes(self) -> cudf.Series:
"""
Return Series of codes as well as the index.
"""
Expand All @@ -129,13 +129,13 @@ def codes(self) -> "cudf.Series":
return cudf.Series(self._column.codes, index=index)

@property
def ordered(self) -> Optional[bool]:
def ordered(self) -> bool | None:
"""
Whether the categories have an ordered relationship.
"""
return self._column.ordered

def as_ordered(self, inplace: bool = False) -> Optional[SeriesOrIndex]:
def as_ordered(self, inplace: bool = False) -> SeriesOrIndex | None:
"""
Set the Categorical to be ordered.
Expand Down Expand Up @@ -192,7 +192,7 @@ def as_ordered(self, inplace: bool = False) -> Optional[SeriesOrIndex]:
self._column.as_ordered(), inplace=inplace
)

def as_unordered(self, inplace: bool = False) -> Optional[SeriesOrIndex]:
def as_unordered(self, inplace: bool = False) -> SeriesOrIndex | None:
"""
Set the Categorical to be unordered.
Expand Down Expand Up @@ -262,7 +262,7 @@ def as_unordered(self, inplace: bool = False) -> Optional[SeriesOrIndex]:

def add_categories(
self, new_categories: Any, inplace: bool = False
) -> Optional[SeriesOrIndex]:
) -> SeriesOrIndex | None:
"""
Add new categories.
Expand Down Expand Up @@ -347,7 +347,7 @@ def add_categories(

def remove_categories(
self, removals: Any, inplace: bool = False,
) -> Optional[SeriesOrIndex]:
) -> SeriesOrIndex | None:
"""
Remove the specified categories.
Expand Down Expand Up @@ -441,7 +441,7 @@ def set_categories(
ordered: bool = False,
rename: bool = False,
inplace: bool = False,
) -> Optional[SeriesOrIndex]:
) -> SeriesOrIndex | None:
"""
Set the categories to the specified new_categories.
Expand Down Expand Up @@ -535,7 +535,7 @@ def reorder_categories(
new_categories: Any,
ordered: bool = False,
inplace: bool = False,
) -> Optional[SeriesOrIndex]:
) -> SeriesOrIndex | None:
"""
Reorder categories as specified in new_categories.
Expand Down Expand Up @@ -624,8 +624,8 @@ class CategoricalColumn(column.ColumnBase):
"""

dtype: cudf.core.dtypes.CategoricalDtype
_codes: Optional[NumericalColumn]
_children: Tuple[NumericalColumn]
_codes: NumericalColumn | None
_children: tuple[NumericalColumn]

def __init__(
self,
Expand All @@ -634,7 +634,7 @@ def __init__(
size: int = None,
offset: int = 0,
null_count: int = None,
children: Tuple["column.ColumnBase", ...] = (),
children: tuple[column.ColumnBase, ...] = (),
):

if size is None:
Expand Down Expand Up @@ -671,8 +671,8 @@ def __contains__(self, item: ScalarLike) -> bool:
return False
return self._encode(item) in self.as_numerical

def serialize(self) -> Tuple[dict, list]:
header: Dict[Any, Any] = {}
def serialize(self) -> tuple[dict, list]:
header: dict[Any, Any] = {}
frames = []
header["type-serialized"] = pickle.dumps(type(self))
header["dtype"], dtype_frames = self.dtype.serialize()
Expand Down Expand Up @@ -729,23 +729,23 @@ def set_base_data(self, value):

def _process_values_for_isin(
self, values: Sequence
) -> Tuple[ColumnBase, ColumnBase]:
) -> tuple[ColumnBase, ColumnBase]:
lhs = self
# We need to convert values to same type as self,
# hence passing dtype=self.dtype
rhs = cudf.core.column.as_column(values, dtype=self.dtype)
return lhs, rhs

def set_base_mask(self, value: Optional[Buffer]):
def set_base_mask(self, value: Buffer | None):
super().set_base_mask(value)
self._codes = None

def set_base_children(self, value: Tuple[ColumnBase, ...]):
def set_base_children(self, value: tuple[ColumnBase, ...]):
super().set_base_children(value)
self._codes = None

@property
def children(self) -> Tuple[NumericalColumn]:
def children(self) -> tuple[NumericalColumn]:
if self._children is None:
codes_column = self.base_children[0]

Expand Down Expand Up @@ -788,7 +788,7 @@ def codes(self) -> NumericalColumn:
return cast(cudf.core.column.NumericalColumn, self._codes)

@property
def ordered(self) -> Optional[bool]:
def ordered(self) -> bool | None:
return self.dtype.ordered

@ordered.setter
Expand Down Expand Up @@ -842,7 +842,7 @@ def _fill(
begin: int,
end: int,
inplace: bool = False,
) -> "column.ColumnBase":
) -> column.ColumnBase:
if end <= begin or begin >= self.size:
return self if inplace else self.copy()

Expand All @@ -858,7 +858,7 @@ def _fill(

def slice(
self, start: int, stop: int, stride: int = None
) -> "column.ColumnBase":
) -> column.ColumnBase:
codes = self.codes.slice(start, stop, stride)
return cudf.core.column.build_categorical_column(
categories=self.categories,
Expand Down Expand Up @@ -909,7 +909,7 @@ def normalize_binop_value(self, other: ScalarLike) -> CategoricalColumn:

def sort_by_values(
self, ascending: bool = True, na_position="last"
) -> Tuple[CategoricalColumn, NumericalColumn]:
) -> tuple[CategoricalColumn, NumericalColumn]:
codes, inds = self.as_numerical.sort_by_values(ascending, na_position)
col = column.build_categorical_column(
categories=self.dtype.categories._values,
Expand Down Expand Up @@ -991,7 +991,7 @@ def values(self):
"""
raise NotImplementedError("cudf.Categorical is not yet implemented")

def clip(self, lo: ScalarLike, hi: ScalarLike) -> "column.ColumnBase":
def clip(self, lo: ScalarLike, hi: ScalarLike) -> column.ColumnBase:
return (
self.astype(self.categories.dtype).clip(lo, hi).astype(self.dtype)
)
Expand Down Expand Up @@ -1329,7 +1329,7 @@ def memory_usage(self) -> int:

def _mimic_inplace(
self, other_col: ColumnBase, inplace: bool = False
) -> Optional[ColumnBase]:
) -> ColumnBase | None:
out = super()._mimic_inplace(other_col, inplace=inplace)
if inplace and isinstance(other_col, CategoricalColumn):
self._codes = other_col._codes
Expand Down Expand Up @@ -1572,7 +1572,7 @@ def as_unordered(self):


def _create_empty_categorical_column(
categorical_column: CategoricalColumn, dtype: "CategoricalDtype"
categorical_column: CategoricalColumn, dtype: CategoricalDtype
) -> CategoricalColumn:
return column.build_categorical_column(
categories=column.as_column(dtype.categories),
Expand Down
Loading

0 comments on commit 54b16b9

Please sign in to comment.