Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions python/pyspark/pandas/typedef/typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import typing
from collections.abc import Iterable
from inspect import isclass
from typing import Any, Callable, Generic, List, Tuple, Union, Type, get_type_hints
from typing import Any, Callable, Generic, List, Optional, Tuple, Union, Type, get_type_hints

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -127,15 +127,15 @@ def __repr__(self) -> str:


class IndexNameTypeHolder:
name = None
tpe = None
short_name = "IndexNameType"
name: Optional[str] = None
tpe: Optional[Union[type, Dtype]] = None
short_name: str = "IndexNameType"


class NameTypeHolder:
name = None
tpe = None
short_name = "NameType"
name: Optional[str] = None
tpe: Optional[Union[type, Dtype]] = None
short_name: str = "NameType"


def as_spark_type(
Expand Down Expand Up @@ -726,7 +726,7 @@ def create_type_for_series_type(param: Any) -> Type[SeriesType]:
new_class: Type[NameTypeHolder]
if isinstance(param, ExtensionDtype):
new_class = type(NameTypeHolder.short_name, (NameTypeHolder,), {})
new_class.tpe = param # type: ignore[assignment]
new_class.tpe = param
else:
if LooseVersion(pd.__version__) < "3.0.0":
new_class = param.type if isinstance(param, np.dtype) else param
Expand Down Expand Up @@ -893,13 +893,11 @@ def _new_type_holders(
new_param.name = param.start
if LooseVersion(pd.__version__) < "3.0.0":
if isinstance(param.stop, ExtensionDtype):
new_param.tpe = param.stop # type: ignore[assignment]
new_param.tpe = param.stop
else:
# When the given argument is a numpy's dtype instance.
new_param.tpe = (
param.stop.type # type: ignore[assignment]
if isinstance(param.stop, np.dtype)
else param.stop
param.stop.type if isinstance(param.stop, np.dtype) else param.stop
)
else:
new_param.tpe = param.stop
Expand All @@ -914,13 +912,9 @@ def _new_type_holders(
)
if LooseVersion(pd.__version__) < "3.0.0":
if isinstance(param, ExtensionDtype):
new_type.tpe = param # type: ignore[assignment]
new_type.tpe = param
else:
new_type.tpe = (
param.type # type: ignore[assignment]
if isinstance(param, np.dtype)
else param
)
new_type.tpe = param.type if isinstance(param, np.dtype) else param
else:
new_type.tpe = param
new_types.append(new_type)
Expand Down