Skip to content

Commit 7dfa8d4

Browse files
anmyachevvnlitvinov
authored andcommitted
first using notations
1 parent 2705687 commit 7dfa8d4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pandas/_typing.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
import numpy as np
55

66
from pandas.core.dtypes.dtypes import ExtensionDtype
7-
from pandas.core.dtypes.generic import ABCExtensionArray
7+
from pandas.core.dtypes.generic import (
8+
ABCExtensionArray, ABCIndexClass, ABCSeries)
9+
10+
# using a certain style for notations (without ABC prefix)
11+
IndexLike = Union[ABCIndexClass]
12+
SeriesLike = Union[ABCSeries]
813

914
ArrayLike = Union[ABCExtensionArray, np.ndarray]
1015
Dtype = Union[str, np.dtype, ExtensionDtype]
1116
FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
17+
IndexLikeOrNdarray = Union[IndexLike, np.ndarray]

pandas/core/tools/datetimes.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@
1818
from pandas.core.dtypes.generic import ABCDataFrame, ABCIndexClass, ABCSeries
1919
from pandas.core.dtypes.missing import notna
2020

21+
from pandas._typing import (
22+
ArrayLike, IndexLike, IndexLikeOrNdarray, SeriesLike, Union)
2123
from pandas.core import algorithms
2224

2325

26+
# notations
27+
IntFltStrDateLisTuplArrSer = Union[int, float, str, list, tuple,
28+
datetime, ArrayLike, SeriesLike]
29+
30+
2431
def _guess_datetime_format_for_array(arr, **kwargs):
2532
# Try to guess the format based on the first non-NaN element
2633
non_nan_elements = notna(arr).nonzero()[0]
@@ -60,7 +67,7 @@ def _maybe_cache(arg, format, cache, convert_listlike):
6067
return cache_array
6168

6269

63-
def _box_as_indexlike(dt_array, tz=None, name=None):
70+
def _box_as_indexlike(dt_array: ArrayLike, tz=None, name=None) -> IndexLike:
6471
"""
6572
Properly boxes the ndarray of datetimes to DatetimeIndex
6673
if it is possible or to generic Index instead
@@ -86,7 +93,9 @@ def _box_as_indexlike(dt_array, tz=None, name=None):
8693
return Index(dt_array, name=name)
8794

8895

89-
def _convert_and_box_cache(arg, cache_array, box, name=None):
96+
def _convert_and_box_cache(arg: IntFltStrDateLisTuplArrSer,
97+
cache_array: SeriesLike,
98+
box: bool, name=None) -> IndexLikeOrNdarray:
9099
"""
91100
Convert array of dates with a cache and box the result
92101

0 commit comments

Comments
 (0)