Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/pandas/_typing.py : 73%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from pathlib import Path
2from typing import (
3 IO,
4 TYPE_CHECKING,
5 Any,
6 AnyStr,
7 Callable,
8 Collection,
9 Dict,
10 Hashable,
11 List,
12 Mapping,
13 Optional,
14 TypeVar,
15 Union,
16)
18import numpy as np
20# To prevent import cycles place any internal imports in the branch below
21# and use a string literal forward reference to it in subsequent types
22# https://mypy.readthedocs.io/en/latest/common_issues.html#import-cycles
23if TYPE_CHECKING:
24 from pandas._libs import Period, Timedelta, Timestamp # noqa: F401
25 from pandas.core.arrays.base import ExtensionArray # noqa: F401
26 from pandas.core.dtypes.dtypes import ExtensionDtype # noqa: F401
27 from pandas.core.indexes.base import Index # noqa: F401
28 from pandas.core.generic import NDFrame # noqa: F401
29 from pandas import Interval # noqa: F401
30 from pandas.core.series import Series # noqa: F401
31 from pandas.core.frame import DataFrame # noqa: F401
33# array-like
35AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray)
36ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray)
38# scalars
40PythonScalar = Union[str, int, float, bool]
41DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta")
42PandasScalar = Union["Period", "Timestamp", "Timedelta", "Interval"]
43Scalar = Union[PythonScalar, PandasScalar]
45# other
47Dtype = Union[str, np.dtype, "ExtensionDtype"]
48FilePathOrBuffer = Union[str, Path, IO[AnyStr]]
50# FrameOrSeriesUnion means either a DataFrame or a Series. E.g.
51# `def func(a: FrameOrSeriesUnion) -> FrameOrSeriesUnion: ...` means that if a Series
52# is passed in, either a Series or DataFrame is returned, and if a DataFrame is passed
53# in, either a DataFrame or a Series is returned.
54FrameOrSeriesUnion = Union["DataFrame", "Series"]
56# FrameOrSeries is stricter and ensures that the same subclass of NDFrame always is
57# used. E.g. `def func(a: FrameOrSeries) -> FrameOrSeries: ...` means that if a
58# Series is passed into a function, a Series is always returned and if a DataFrame is
59# passed in, a DataFrame is always returned.
60FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame")
62Axis = Union[str, int]
63Label = Optional[Hashable]
64Level = Union[Label, int]
65Ordered = Optional[bool]
66JSONSerializable = Union[PythonScalar, List, Dict]
67Axes = Collection
69# For functions like rename that convert one label to another
70Renamer = Union[Mapping[Label, Any], Callable[[Label], Label]]
72# to maintain type information across generic functions and parametrization
73T = TypeVar("T")