diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3078619ecac35..d580fcf4fc545 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: - id: absolufy-imports files: ^pandas/ - repo: https://github.com/python/black - rev: 20.8b1 + rev: 21.5b2 hooks: - id: black - repo: https://github.com/codespell-project/codespell diff --git a/doc/source/development/contributing_codebase.rst b/doc/source/development/contributing_codebase.rst index d6ff48ed5fd39..de4ed20e26726 100644 --- a/doc/source/development/contributing_codebase.rst +++ b/doc/source/development/contributing_codebase.rst @@ -169,7 +169,7 @@ submitting code to run the check yourself:: to auto-format your code. Additionally, many editors have plugins that will apply ``black`` as you edit files. -You should use a ``black`` version 20.8b1 as previous versions are not compatible +You should use a ``black`` version 21.5b2 as previous versions are not compatible with the pandas codebase. One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff``: this diff --git a/environment.yml b/environment.yml index bb96235123af3..1eccbf978c2d1 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - cython>=0.29.21 # code checks - - black=20.8b1 + - black=21.5b2 - cpplint - flake8=3.9.2 - flake8-bugbear=21.3.2 # used by flake8, find likely bugs diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 37f5a5730439d..be3498dc0829b 100644 --- a/pandas/_config/config.py +++ b/pandas/_config/config.py @@ -189,7 +189,7 @@ def get_default_val(pat: str): class DictWrapper: - """ provide attribute-style access to a nested dict""" + """provide attribute-style access to a nested dict""" def __init__(self, d: dict[str, Any], prefix: str = ""): object.__setattr__(self, "d", d) @@ -571,7 +571,7 @@ def _get_root(key: str) -> tuple[dict[str, Any], str]: def _is_deprecated(key: str) -> bool: - """ Returns True if the given option has been deprecated """ + """Returns True if the given option has been deprecated""" key = key.lower() return key in _deprecated_options @@ -643,7 +643,7 @@ def _warn_if_deprecated(key: str) -> bool: def _build_option_description(k: str) -> str: - """ Builds a formatted description of a registered option and prints it """ + """Builds a formatted description of a registered option and prints it""" o = _get_registered_option(k) d = _get_deprecated_option(k) @@ -667,7 +667,7 @@ def _build_option_description(k: str) -> str: def pp_options_list(keys: Iterable[str], width=80, _print: bool = False): - """ Builds a concise listing of available options, grouped by prefix """ + """Builds a concise listing of available options, grouped by prefix""" from itertools import groupby from textwrap import wrap diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index 30a31d17fc947..d0f664c323a89 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -7,6 +7,7 @@ class Infinity: """ Provide a positive Infinity comparison method for ranking. """ + def __eq__(self, other) -> bool: ... def __ne__(self, other) -> bool: ... def __lt__(self, other) -> bool: ... @@ -14,11 +15,11 @@ class Infinity: def __gt__(self, other) -> bool: ... def __ge__(self, other) -> bool: ... - class NegInfinity: """ Provide a negative Infinity comparison method for ranking. """ + def __eq__(self, other) -> bool: ... def __ne__(self, other) -> bool: ... def __lt__(self, other) -> bool: ... @@ -26,56 +27,38 @@ class NegInfinity: def __gt__(self, other) -> bool: ... def __ge__(self, other) -> bool: ... - def unique_deltas( arr: np.ndarray, # const int64_t[:] ) -> np.ndarray: ... # np.ndarray[np.int64, ndim=1] - - def is_lexsorted(list_of_arrays: list[np.ndarray]) -> bool: ... - - def groupsort_indexer( index: np.ndarray, # const int64_t[:] ngroups: int, ) -> tuple[ np.ndarray, # ndarray[int64_t, ndim=1] np.ndarray, # ndarray[int64_t, ndim=1] -]: - ... - - +]: ... def kth_smallest( a: np.ndarray, # numeric[:] k: int, -) -> Any: ... # numeric - +) -> Any: ... # numeric # ---------------------------------------------------------------------- # Pairwise correlation/covariance - - def nancorr( mat: np.ndarray, # const float64_t[:, :] cov: bool = False, minp=None, -) -> np.ndarray: # np.ndarray[float64_t, ndim=2] - ... - - +) -> np.ndarray: ... # ndarray[float64_t, ndim=2] def nancorr_spearman( mat: np.ndarray, # ndarray[float64_t, ndim=2] minp: int = 1, -) -> np.ndarray: # np.ndarray[np.float64, ndim=2] - ... - - +) -> np.ndarray: ... # ndarray[float64_t, ndim=2] def nancorr_kendall( mat: np.ndarray, # ndarray[float64_t, ndim=2] minp: int = 1, -) -> np.ndarray: # np.ndarray[float64, ndim=2] - ... +) -> np.ndarray: ... # ndarray[float64_t, ndim=2] # ---------------------------------------------------------------------- @@ -92,58 +75,41 @@ def nancorr_kendall( # uint16_t # uint8_t - def validate_limit(nobs: int | None, limit=None) -> int: ... - - def pad( - old: np.ndarray, # ndarray[algos_t] - new: np.ndarray, # ndarray[algos_t] + old: np.ndarray, # ndarray[algos_t] + new: np.ndarray, # ndarray[algos_t] limit=None, ) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1] - - def pad_inplace( values: np.ndarray, # algos_t[:] - mask: np.ndarray, # uint8_t[:] + mask: np.ndarray, # uint8_t[:] limit=None, ) -> None: ... - - def pad_2d_inplace( values: np.ndarray, # algos_t[:, :] - mask: np.ndarray, # const uint8_t[:, :] + mask: np.ndarray, # const uint8_t[:, :] limit=None, -) -> None: - ... - - +) -> None: ... def backfill( old: np.ndarray, # ndarray[algos_t] new: np.ndarray, # ndarray[algos_t] limit=None, -) -> np.ndarray: # np.ndarray[np.intp, ndim=1] - ... - +) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1] def backfill_inplace( values: np.ndarray, # algos_t[:] - mask: np.ndarray, # uint8_t[:] + mask: np.ndarray, # uint8_t[:] limit=None, ) -> None: ... - - def backfill_2d_inplace( values: np.ndarray, # algos_t[:, :] - mask: np.ndarray, # const uint8_t[:, :] + mask: np.ndarray, # const uint8_t[:, :] limit=None, ) -> None: ... - - def is_monotonic( arr: np.ndarray, # ndarray[algos_t, ndim=1] - timelike: bool -) -> tuple[bool, bool, bool]: - ... + timelike: bool, +) -> tuple[bool, bool, bool]: ... # ---------------------------------------------------------------------- # rank_1d, rank_2d @@ -155,7 +121,6 @@ def is_monotonic( # uint64_t # int64_t - def rank_1d( values: np.ndarray, # ndarray[rank_t, ndim=1] labels: np.ndarray, # const int64_t[:] @@ -165,8 +130,6 @@ def rank_1d( pct: bool = ..., na_option=..., ) -> np.ndarray: ... # np.ndarray[float64_t, ndim=1] - - def rank_2d( in_arr: np.ndarray, # ndarray[rank_t, ndim=2] axis: int = ..., @@ -176,8 +139,6 @@ def rank_2d( na_option=..., pct: bool = ..., ) -> np.ndarray: ... # np.ndarray[float64_t, ndim=1] - - def diff_2d( arr: np.ndarray, # ndarray[diff_t, ndim=2] out: np.ndarray, # ndarray[out_t, ndim=2] @@ -185,109 +146,243 @@ def diff_2d( axis: int, datetimelike: bool = ..., ) -> None: ... - - def ensure_platform_int(arr: object) -> np.ndarray: ... - def ensure_object(arr: object) -> np.ndarray: ... - def ensure_float64(arr: object, copy=True) -> np.ndarray: ... - def ensure_float32(arr: object, copy=True) -> np.ndarray: ... - def ensure_int8(arr: object, copy=True) -> np.ndarray: ... - def ensure_int16(arr: object, copy=True) -> np.ndarray: ... - def ensure_int32(arr: object, copy=True) -> np.ndarray: ... - def ensure_int64(arr: object, copy=True) -> np.ndarray: ... - def ensure_uint8(arr: object, copy=True) -> np.ndarray: ... - def ensure_uint16(arr: object, copy=True) -> np.ndarray: ... - def ensure_uint32(arr: object, copy=True) -> np.ndarray: ... - def ensure_uint64(arr: object, copy=True) -> np.ndarray: ... - - -def take_1d_int8_int8(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int8_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int8_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int8_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int16_int16(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int16_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int16_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int16_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int32_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int32_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int32_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int64_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_int64_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_float32_float32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_float32_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_float64_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_object_object(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_bool_bool(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_1d_bool_object(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... - -def take_2d_axis0_int8_int8(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int8_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int8_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int8_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int16_int16(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int16_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int16_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int16_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int32_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int32_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int32_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int64_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_int64_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_float32_float32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_float32_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_float64_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_object_object(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_bool_bool(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis0_bool_object(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... - -def take_2d_axis1_int8_int8(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int8_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int8_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int8_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int16_int16(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int16_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int16_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int16_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int32_int32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int32_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int32_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int64_int64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_int64_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_float32_float32(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_float32_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_float64_float64(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_object_object(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_bool_bool(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_axis1_bool_object(values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=...) -> None: ... - -def take_2d_multi_int8_int8(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int8_int32(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int8_int64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int8_float64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int16_int16(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int16_int32(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int16_int64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int16_float64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int32_int32(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int32_int64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int32_float64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int64_float64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_float32_float32(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_float32_float64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_float64_float64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_object_object(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_bool_bool(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_bool_object(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... -def take_2d_multi_int64_int64(values: np.ndarray, indexer, out: np.ndarray, fill_value=...) -> None: ... +def take_1d_int8_int8( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int8_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int8_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int8_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int16_int16( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int16_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int16_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int16_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int32_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int32_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int32_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int64_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_int64_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_float32_float32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_float32_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_float64_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_object_object( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_bool_bool( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_1d_bool_object( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int8_int8( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int8_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int8_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int8_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int16_int16( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int16_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int16_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int16_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int32_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int32_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int32_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int64_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_int64_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_float32_float32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_float32_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_float64_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_object_object( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_bool_bool( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis0_bool_object( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int8_int8( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int8_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int8_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int8_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int16_int16( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int16_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int16_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int16_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int32_int32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int32_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int32_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int64_int64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_int64_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_float32_float32( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_float32_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_float64_float64( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_object_object( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_bool_bool( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_axis1_bool_object( + values: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int8_int8( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int8_int32( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int8_int64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int8_float64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int16_int16( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int16_int32( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int16_int64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int16_float64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int32_int32( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int32_int64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int32_float64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int64_float64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_float32_float32( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_float32_float64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_float64_float64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_object_object( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_bool_bool( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_bool_object( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... +def take_2d_multi_int64_int64( + values: np.ndarray, indexer, out: np.ndarray, fill_value=... +) -> None: ... diff --git a/pandas/_libs/arrays.pyi b/pandas/_libs/arrays.pyi index 0ca501c5b712c..67af9653fc75a 100644 --- a/pandas/_libs/arrays.pyi +++ b/pandas/_libs/arrays.pyi @@ -10,36 +10,25 @@ from pandas._typing import ( class NDArrayBacked: _dtype: DtypeObj _ndarray: np.ndarray - def __init__(self, values: np.ndarray, dtype: DtypeObj): ... - @classmethod def _simple_new(cls, values: np.ndarray, dtype: DtypeObj): ... - def _from_backing_data(self, values: np.ndarray): ... - def __setstate__(self, state): ... - def __len__(self) -> int: ... - @property def shape(self) -> Shape: ... - @property def ndim(self) -> int: ... - @property def size(self) -> int: ... - @property def nbytes(self) -> int: ... - def copy(self): ... def delete(self, loc, axis=0): ... def swapaxes(self, axis1, axis2): ... def repeat(self, repeats: int | Sequence[int], axis: int | None = ...): ... def reshape(self, *args, **kwargs): ... def ravel(self, order="C"): ... - @property def T(self): ... diff --git a/pandas/_libs/groupby.pyi b/pandas/_libs/groupby.pyi index 8721624e9881c..7b1dcbe562123 100644 --- a/pandas/_libs/groupby.pyi +++ b/pandas/_libs/groupby.pyi @@ -3,128 +3,111 @@ from typing import Literal import numpy as np def group_median_float64( - out: np.ndarray, # ndarray[float64_t, ndim=2] - counts: np.ndarray, # ndarray[int64_t] - values: np.ndarray, # ndarray[float64_t, ndim=2] - labels: np.ndarray, # ndarray[int64_t] + out: np.ndarray, # ndarray[float64_t, ndim=2] + counts: np.ndarray, # ndarray[int64_t] + values: np.ndarray, # ndarray[float64_t, ndim=2] + labels: np.ndarray, # ndarray[int64_t] min_count: int = ..., # Py_ssize_t ) -> None: ... - def group_cumprod_float64( - out: np.ndarray, # float64_t[:, ::1] + out: np.ndarray, # float64_t[:, ::1] values: np.ndarray, # const float64_t[:, :] labels: np.ndarray, # const int64_t[:] ngroups: int, is_datetimelike: bool, skipna: bool = ..., ) -> None: ... - def group_cumsum( - out: np.ndarray, # numeric[:, ::1] + out: np.ndarray, # numeric[:, ::1] values: np.ndarray, # ndarray[numeric, ndim=2] labels: np.ndarray, # const int64_t[:] ngroups: int, is_datetimelike: bool, skipna: bool = ..., ) -> None: ... - - def group_shift_indexer( - out: np.ndarray, # int64_t[::1] + out: np.ndarray, # int64_t[::1] labels: np.ndarray, # const int64_t[:] ngroups: int, periods: int, ) -> None: ... - - def group_fillna_indexer( - out: np.ndarray, # ndarray[int64_t] + out: np.ndarray, # ndarray[int64_t] labels: np.ndarray, # ndarray[int64_t] - mask: np.ndarray, # ndarray[uint8_t] + mask: np.ndarray, # ndarray[uint8_t] direction: Literal["ffill", "bfill"], - limit: int, # int64_t + limit: int, # int64_t dropna: bool, ) -> None: ... - - def group_any_all( - out: np.ndarray, # uint8_t[::1] + out: np.ndarray, # uint8_t[::1] values: np.ndarray, # const uint8_t[::1] labels: np.ndarray, # const int64_t[:] - mask: np.ndarray, # const uint8_t[::1] + mask: np.ndarray, # const uint8_t[::1] val_test: Literal["any", "all"], skipna: bool, ) -> None: ... - def group_add( - out: np.ndarray, # complexfloating_t[:, ::1] + out: np.ndarray, # complexfloating_t[:, ::1] counts: np.ndarray, # int64_t[::1] values: np.ndarray, # ndarray[complexfloating_t, ndim=2] labels: np.ndarray, # const intp_t[:] - min_count: int = ... + min_count: int = ..., ) -> None: ... - def group_prod( - out: np.ndarray, # floating[:, ::1] + out: np.ndarray, # floating[:, ::1] counts: np.ndarray, # int64_t[::1] values: np.ndarray, # ndarray[floating, ndim=2] labels: np.ndarray, # const intp_t[:] - min_count: int = ... + min_count: int = ..., ) -> None: ... - def group_var( - out: np.ndarray, # floating[:, ::1] - counts: np.ndarray, # int64_t[::1] - values: np.ndarray, # ndarray[floating, ndim=2] - labels: np.ndarray, # const intp_t[:] + out: np.ndarray, # floating[:, ::1] + counts: np.ndarray, # int64_t[::1] + values: np.ndarray, # ndarray[floating, ndim=2] + labels: np.ndarray, # const intp_t[:] min_count: int = ..., # Py_ssize_t - ddof: int = ..., # int64_t + ddof: int = ..., # int64_t ) -> None: ... - def group_mean( - out: np.ndarray, # floating[:, ::1] + out: np.ndarray, # floating[:, ::1] counts: np.ndarray, # int64_t[::1] values: np.ndarray, # ndarray[floating, ndim=2] labels: np.ndarray, # const intp_t[:] - min_count: int = ... + min_count: int = ..., ) -> None: ... - def group_ohlc( - out: np.ndarray, # floating[:, ::1] + out: np.ndarray, # floating[:, ::1] counts: np.ndarray, # int64_t[::1] values: np.ndarray, # ndarray[floating, ndim=2] labels: np.ndarray, # const intp_t[:] - min_count: int = ... + min_count: int = ..., ) -> None: ... - def group_quantile( - out: np.ndarray, # ndarray[float64_t] + out: np.ndarray, # ndarray[float64_t] values: np.ndarray, # ndarray[numeric, ndim=1] labels: np.ndarray, # ndarray[int64_t] - mask: np.ndarray, # ndarray[uint8_t] - q: float, # float64_t + mask: np.ndarray, # ndarray[uint8_t] + q: float, # float64_t interpolation: Literal["linear", "lower", "higher", "nearest", "midpoint"], ) -> None: ... - def group_last( - out: np.ndarray, # rank_t[:, ::1] - counts: np.ndarray, # int64_t[::1] - values: np.ndarray, # ndarray[rank_t, ndim=2] - labels: np.ndarray, # const int64_t[:] + out: np.ndarray, # rank_t[:, ::1] + counts: np.ndarray, # int64_t[::1] + values: np.ndarray, # ndarray[rank_t, ndim=2] + labels: np.ndarray, # const int64_t[:] min_count: int = ..., # Py_ssize_t ) -> None: ... - def group_nth( - out: np.ndarray, # rank_t[:, ::1] - counts: np.ndarray, # int64_t[::1] - values: np.ndarray, # ndarray[rank_t, ndim=2] - labels: np.ndarray, # const int64_t[:] - min_count: int = ..., # int64_t - rank: int = ..., # int64_t + out: np.ndarray, # rank_t[:, ::1] + counts: np.ndarray, # int64_t[::1] + values: np.ndarray, # ndarray[rank_t, ndim=2] + labels: np.ndarray, # const int64_t[:] + min_count: int = ..., # int64_t + rank: int = ..., # int64_t ) -> None: ... - def group_rank( - out: np.ndarray, # float64_t[:, ::1] + out: np.ndarray, # float64_t[:, ::1] values: np.ndarray, # ndarray[rank_t, ndim=2] labels: np.ndarray, # const int64_t[:] ngroups: int, @@ -134,35 +117,31 @@ def group_rank( pct: bool = ..., na_option: Literal["keep", "top", "bottom"] = ..., ) -> None: ... - def group_max( - out: np.ndarray, # groupby_t[:, ::1] + out: np.ndarray, # groupby_t[:, ::1] counts: np.ndarray, # int64_t[::1] values: np.ndarray, # ndarray[groupby_t, ndim=2] labels: np.ndarray, # const int64_t[:] min_count: int = ..., ) -> None: ... - def group_min( - out: np.ndarray, # groupby_t[:, ::1] + out: np.ndarray, # groupby_t[:, ::1] counts: np.ndarray, # int64_t[::1] values: np.ndarray, # ndarray[groupby_t, ndim=2] labels: np.ndarray, # const int64_t[:] min_count: int = ..., ) -> None: ... - def group_cummin( - out: np.ndarray, # groupby_t[:, ::1] - values: np.ndarray, # ndarray[groupby_t, ndim=2] - labels: np.ndarray, # const int64_t[:] + out: np.ndarray, # groupby_t[:, ::1] + values: np.ndarray, # ndarray[groupby_t, ndim=2] + labels: np.ndarray, # const int64_t[:] ngroups: int, is_datetimelike: bool, ) -> None: ... - def group_cummax( - out: np.ndarray, # groupby_t[:, ::1] - values: np.ndarray, # ndarray[groupby_t, ndim=2] - labels: np.ndarray, # const int64_t[:] + out: np.ndarray, # groupby_t[:, ::1] + values: np.ndarray, # ndarray[groupby_t, ndim=2] + labels: np.ndarray, # const int64_t[:] ngroups: int, is_datetimelike: bool, ) -> None: ... diff --git a/pandas/_libs/hashtable.pyi b/pandas/_libs/hashtable.pyi index 0612acd25a5d5..5a1b98b190dbc 100644 --- a/pandas/_libs/hashtable.pyi +++ b/pandas/_libs/hashtable.pyi @@ -10,18 +10,14 @@ def unique_label_indices( labels: np.ndarray, # const int64_t[:] ) -> np.ndarray: ... - class Factorizer: count: int - def __init__(self, size_hint: int): ... def get_count(self) -> int: ... - class ObjectFactorizer(Factorizer): table: PyObjectHashTable uniques: ObjectVector - def factorize( self, values: np.ndarray, # ndarray[object] @@ -30,11 +26,9 @@ class ObjectFactorizer(Factorizer): na_value=..., ) -> np.ndarray: ... # np.ndarray[intp] - class Int64Factorizer(Factorizer): table: Int64HashTable uniques: Int64Vector - def factorize( self, values: np.ndarray, # const int64_t[:] @@ -43,7 +37,6 @@ class Int64Factorizer(Factorizer): na_value=..., ) -> np.ndarray: ... # np.ndarray[intp] - class Int64Vector: def __init__(self): ... def __len__(self) -> int: ... @@ -114,7 +107,6 @@ class ObjectVector: def __len__(self) -> int: ... def to_array(self) -> np.ndarray: ... # np.ndarray[object] - class HashTable: # NB: The base HashTable class does _not_ actually have these methods; # we are putting the here for the sake of mypy to avoid @@ -124,37 +116,31 @@ class HashTable: def __contains__(self, key: Hashable) -> bool: ... def sizeof(self, deep: bool = ...) -> int: ... def get_state(self) -> dict[str, int]: ... - # TODO: `item` type is subclass-specific def get_item(self, item): ... # TODO: return type? def set_item(self, item) -> None: ... - # FIXME: we don't actually have this for StringHashTable or ObjectHashTable? def map( self, - keys: np.ndarray, # np.ndarray[subclass-specific] - values: np.ndarray, # const int64_t[:] values + keys: np.ndarray, # np.ndarray[subclass-specific] + values: np.ndarray, # const int64_t[:] ) -> None: ... - def map_locations( self, values: np.ndarray, # np.ndarray[subclass-specific] ) -> None: ... - def lookup( self, values: np.ndarray, # np.ndarray[subclass-specific] - ) -> np.ndarray: ... # np.ndarray[np.intp] - + ) -> np.ndarray: ... # np.ndarray[np.intp] def get_labels( self, values: np.ndarray, # np.ndarray[subclass-specific] - uniques, # SubclassTypeVector + uniques, # SubclassTypeVector count_prior: int = ..., na_sentinel: int = ..., na_value: object = ..., - ) -> np.ndarray: ... # np.ndarray[intp_t] - + ) -> np.ndarray: ... # np.ndarray[intp_t] def unique( self, values: np.ndarray, # np.ndarray[subclass-specific] @@ -163,11 +149,10 @@ class HashTable: np.ndarray, # np.ndarray[subclass-specific] np.ndarray, # np.ndarray[np.intp], ] | np.ndarray: ... # np.ndarray[subclass-specific] - def _unique( self, values: np.ndarray, # np.ndarray[subclass-specific] - uniques, # FooVector + uniques, # FooVector count_prior: int = ..., na_sentinel: int = ..., na_value: object = ..., @@ -177,7 +162,6 @@ class HashTable: np.ndarray, # np.ndarray[subclass-specific] np.ndarray, # np.ndarray[np.intp], ] | np.ndarray: ... # np.ndarray[subclass-specific] - def factorize( self, values: np.ndarray, # np.ndarray[subclass-specific] @@ -185,9 +169,9 @@ class HashTable: na_value: object = ..., mask=..., ) -> tuple[ - np.ndarray, # np.ndarray[subclass-specific] - np.ndarray, # np.ndarray[np.intp], - ]: ... + np.ndarray, # np.ndarray[subclass-specific] + np.ndarray, # np.ndarray[np.intp], + ]: ... class Complex128HashTable(HashTable): ... class Complex64HashTable(HashTable): ... @@ -211,46 +195,33 @@ class UInt64HashTable(HashTable): ... class UInt32HashTable(HashTable): ... class UInt16HashTable(HashTable): ... class UInt8HashTable(HashTable): ... - class StringHashTable(HashTable): ... class PyObjectHashTable(HashTable): ... - def duplicated_int64( values: np.ndarray, # const int64_t[:] values keep: Literal["last", "first", False] = ..., ) -> np.ndarray: ... # np.ndarray[bool] + # TODO: Is it actually bool or is it uint8? def mode_int64( values: np.ndarray, # const int64_t[:] values dropna: bool, ) -> np.ndarray: ... # np.ndarray[np.int64] - def value_count_int64( values: np.ndarray, # const int64_t[:] dropna: bool, -) -> tuple[ - np.ndarray, # np.ndarray[np.int64] - np.ndarray, # np.ndarray[np.int64] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64] def duplicated( values: np.ndarray, keep: Literal["last", "first", False] = ..., ) -> np.ndarray: ... # np.ndarray[bool] - def mode(values: np.ndarray, dropna: bool) -> np.ndarray: ... - def value_count( values: np.ndarray, dropna: bool, -) -> tuple[ - np.ndarray, - np.ndarray, # np.ndarray[np.int64] -]: ... - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # arr and values should have same dtype def ismember( diff --git a/pandas/_libs/index.pyi b/pandas/_libs/index.pyi index 979619c3d14c4..6bb332435be63 100644 --- a/pandas/_libs/index.pyi +++ b/pandas/_libs/index.pyi @@ -2,32 +2,26 @@ import numpy as np class IndexEngine: over_size_threshold: bool - def __init__(self, vgetter, n: int): ... - def __contains__(self, val: object) -> bool: ... - # -> int | slice | np.ndarray[bool] def get_loc(self, val: object) -> int | slice | np.ndarray: ... - def sizeof(self, deep: bool = False) -> int: ... def __sizeof__(self) -> int: ... - @property def is_unique(self) -> bool: ... - @property def is_monotonic_increasing(self) -> bool: ... - @property def is_monotonic_decreasing(self) -> bool: ... - - def get_backfill_indexer(self, other: np.ndarray, limit: int | None =...) -> np.ndarray: ... - def get_pad_indexer(self, other: np.ndarray, limit: int | None =...) -> np.ndarray: ... - + def get_backfill_indexer( + self, other: np.ndarray, limit: int | None = ... + ) -> np.ndarray: ... + def get_pad_indexer( + self, other: np.ndarray, limit: int | None = ... + ) -> np.ndarray: ... @property def is_mapping_populated(self) -> bool: ... - def clear_mapping(self): ... def get_indexer(self, values: np.ndarray) -> np.ndarray: ... # np.ndarray[np.intp] def get_indexer_non_unique( @@ -38,45 +32,35 @@ class IndexEngine: np.ndarray, # np.ndarray[np.intp] ]: ... - class Float64Engine(IndexEngine): ... class Float32Engine(IndexEngine): ... - class Int64Engine(IndexEngine): ... class Int32Engine(IndexEngine): ... class Int16Engine(IndexEngine): ... class Int8Engine(IndexEngine): ... - class UInt64Engine(IndexEngine): ... class UInt32Engine(IndexEngine): ... class UInt16Engine(IndexEngine): ... class UInt8Engine(IndexEngine): ... - class ObjectEngine(IndexEngine): ... - class DatetimeEngine(Int64Engine): ... class TimedeltaEngine(DatetimeEngine): ... class PeriodEngine(Int64Engine): ... - class BaseMultiIndexCodesEngine: levels: list[np.ndarray] offsets: np.ndarray # ndarray[uint64_t, ndim=1] - def __init__( self, levels: list[np.ndarray], # all entries hashable labels: list[np.ndarray], # all entries integer-dtyped offsets: np.ndarray, # np.ndarray[np.uint64, ndim=1] ): ... - def get_indexer( self, target: np.ndarray, # np.ndarray[object] - ) -> np.ndarray: ... # np.ndarray[np.intp] - + ) -> np.ndarray: ... # np.ndarray[np.intp] def _extract_level_codes(self, target: object): ... - def get_indexer_with_fill( self, target: np.ndarray, # np.ndarray[object] of tuples diff --git a/pandas/_libs/internals.pyi b/pandas/_libs/internals.pyi index 74ca311b35ed7..d6fac14d3ee6e 100644 --- a/pandas/_libs/internals.pyi +++ b/pandas/_libs/internals.pyi @@ -16,52 +16,36 @@ from pandas.core.arrays._mixins import NDArrayBackedExtensionArray from pandas.core.internals.blocks import Block as B def slice_len(slc: slice, objlen: int = ...) -> int: ... - - def get_blkno_indexers( blknos: np.ndarray, # int64_t[:] group: bool = ..., ) -> list[tuple[int, slice | np.ndarray]]: ... - - def get_blkno_placements( blknos: np.ndarray, group: bool = ..., ) -> Iterator[tuple[int, BlockPlacement]]: ... - class BlockPlacement: def __init__(self, val: int | slice | np.ndarray): ... - @property def indexer(self) -> np.ndarray | slice: ... - @property def as_array(self) -> np.ndarray: ... - @property def is_slice_like(self) -> bool: ... - @overload def __getitem__(self, loc: slice | Sequence[int]) -> BlockPlacement: ... - @overload def __getitem__(self, loc: int) -> int: ... - def __iter__(self) -> Iterator[int]: ... - def __len__(self) -> int: ... - def delete(self, loc) -> BlockPlacement: ... - def append(self, others: list[BlockPlacement]) -> BlockPlacement: ... - class SharedBlock: _mgr_locs: BlockPlacement ndim: int values: ArrayLike - def __init__(self, values: ArrayLike, placement: BlockPlacement, ndim: int): ... class NumpyBlock(SharedBlock): @@ -72,8 +56,7 @@ class NDArrayBackedBlock(SharedBlock): values: NDArrayBackedExtensionArray def getitem_block_index(self: T, slicer: slice) -> T: ... -class Block(SharedBlock): - ... +class Block(SharedBlock): ... class BlockManager: blocks: tuple[B, ...] @@ -82,7 +65,7 @@ class BlockManager: _is_consolidated: bool _blknos: np.ndarray _blklocs: np.ndarray - - def __init__(self, blocks: tuple[B, ...], axes: list[Index], verify_integrity=True): ... - - def get_slice(self: T, slobj: slice, axis: int=...) -> T: ... + def __init__( + self, blocks: tuple[B, ...], axes: list[Index], verify_integrity=True + ): ... + def get_slice(self: T, slobj: slice, axis: int = ...) -> T: ... diff --git a/pandas/_libs/join.pyi b/pandas/_libs/join.pyi index 4ae3ef0781dde..f73f495cf4d4f 100644 --- a/pandas/_libs/join.pyi +++ b/pandas/_libs/join.pyi @@ -1,144 +1,91 @@ import numpy as np def inner_join( - left: np.ndarray, # const intp_t[:] + left: np.ndarray, # const intp_t[:] right: np.ndarray, # const intp_t[:] max_groups: int, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def left_outer_join( - left: np.ndarray, # const intp_t[:] + left: np.ndarray, # const intp_t[:] right: np.ndarray, # const intp_t[:] max_groups: int, sort: bool = True, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def full_outer_join( - left: np.ndarray, # const intp_t[:] + left: np.ndarray, # const intp_t[:] right: np.ndarray, # const intp_t[:] max_groups: int, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def ffill_indexer( - indexer: np.ndarray # const intp_t[:] + indexer: np.ndarray, # const intp_t[:] ) -> np.ndarray: ... # np.ndarray[np.intp] - - def left_join_indexer_unique( - left: np.ndarray, # ndarray[join_t] + left: np.ndarray, # ndarray[join_t] right: np.ndarray, # ndarray[join_t] ) -> np.ndarray: ... # np.ndarray[np.intp] - - def left_join_indexer( - left: np.ndarray, # ndarray[join_t] + left: np.ndarray, # ndarray[join_t] right: np.ndarray, # ndarray[join_t] ) -> tuple[ np.ndarray, # np.ndarray[join_t] np.ndarray, # np.ndarray[np.intp] np.ndarray, # np.ndarray[np.intp] ]: ... - - def inner_join_indexer( - left: np.ndarray, # ndarray[join_t] + left: np.ndarray, # ndarray[join_t] right: np.ndarray, # ndarray[join_t] ) -> tuple[ np.ndarray, # np.ndarray[join_t] np.ndarray, # np.ndarray[np.intp] np.ndarray, # np.ndarray[np.intp] ]: ... - - def outer_join_indexer( - left: np.ndarray, # ndarray[join_t] + left: np.ndarray, # ndarray[join_t] right: np.ndarray, # ndarray[join_t] ) -> tuple[ np.ndarray, # np.ndarray[join_t] np.ndarray, # np.ndarray[np.intp] np.ndarray, # np.ndarray[np.intp] ]: ... - - def asof_join_backward_on_X_by_Y( - left_values: np.ndarray, # asof_t[:] - right_values: np.ndarray, # asof_t[:] - left_by_values: np.ndarray, # by_t[:] + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + left_by_values: np.ndarray, # by_t[:] right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = True, tolerance=None, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def asof_join_forward_on_X_by_Y( - left_values: np.ndarray, # asof_t[:] - right_values: np.ndarray, # asof_t[:] - left_by_values: np.ndarray, # by_t[:] + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + left_by_values: np.ndarray, # by_t[:] right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = True, tolerance=None, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def asof_join_nearest_on_X_by_Y( - left_values: np.ndarray, # asof_t[:] - right_values: np.ndarray, # asof_t[:] - left_by_values: np.ndarray, # by_t[:] + left_values: np.ndarray, # asof_t[:] + right_values: np.ndarray, # asof_t[:] + left_by_values: np.ndarray, # by_t[:] right_by_values: np.ndarray, # by_t[:] allow_exact_matches: bool = True, tolerance=None, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def asof_join_backward( - left_values: np.ndarray, # asof_t[:] + left_values: np.ndarray, # asof_t[:] right_values: np.ndarray, # asof_t[:] allow_exact_matches: bool = True, tolerance=None, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def asof_join_forward( - left_values: np.ndarray, # asof_t[:] + left_values: np.ndarray, # asof_t[:] right_values: np.ndarray, # asof_t[:] allow_exact_matches: bool = True, tolerance=None, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... - - +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] def asof_join_nearest( - left_values: np.ndarray, # asof_t[:] + left_values: np.ndarray, # asof_t[:] right_values: np.ndarray, # asof_t[:] allow_exact_matches: bool = True, tolerance=None, -) -> tuple[ - np.ndarray, # np.ndarray[np.intp] - np.ndarray, # np.ndarray[np.intp] -]: ... +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.intp] # np.ndarray[np.intp] diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index 47340719a6a04..3f4623638c70e 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -21,19 +21,15 @@ ndarray_obj_2d = np.ndarray from enum import Enum -class NoDefault(Enum): - ... +class NoDefault(Enum): ... no_default: NoDefault - def item_from_zerodim(val: object) -> object: ... def infer_dtype(value: object, skipna: bool = True) -> str: ... - def is_iterator(obj: object) -> bool: ... def is_scalar(val: object) -> bool: ... def is_list_like(obj: object, allow_sets: bool = True) -> bool: ... - def is_period(val: object) -> bool: ... def is_interval(val: object) -> bool: ... def is_decimal(val: object) -> bool: ... @@ -41,12 +37,10 @@ def is_complex(val: object) -> bool: ... def is_bool(val: object) -> bool: ... def is_integer(val: object) -> bool: ... def is_float(val: object) -> bool: ... - def is_interval_array(values: np.ndarray) -> bool: ... def is_datetime64_array(values: np.ndarray) -> bool: ... def is_timedelta_or_timedelta64_array(values: np.ndarray) -> bool: ... def is_datetime_with_singletz_array(values: np.ndarray) -> bool: ... - def is_time_array(values: np.ndarray, skipna: bool = False): ... def is_date_array(values: np.ndarray, skipna: bool = False): ... def is_datetime_array(values: np.ndarray, skipna: bool = False): ... @@ -54,16 +48,15 @@ def is_string_array(values: np.ndarray, skipna: bool = False): ... def is_float_array(values: np.ndarray, skipna: bool = False): ... def is_integer_array(values: np.ndarray, skipna: bool = False): ... def is_bool_array(values: np.ndarray, skipna: bool = False): ... - def fast_unique_multiple_list_gen(gen: Generator, sort: bool = True) -> list: ... def fast_unique_multiple_list(lists: list, sort: bool = True) -> list: ... def fast_unique_multiple(arrays: list, sort: bool = True) -> list: ... - def map_infer( - arr: np.ndarray, f: Callable[[Any], Any], convert: bool = True, ignore_na: bool = False + arr: np.ndarray, + f: Callable[[Any], Any], + convert: bool = True, + ignore_na: bool = False, ) -> np.ndarray: ... - - @overload # both convert_datetime and convert_to_nullable_integer False -> np.ndarray def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -77,7 +70,6 @@ def maybe_convert_objects( convert_to_nullable_integer: Literal[False] = ..., dtype_if_all_nat: DtypeObj | None = ..., ) -> np.ndarray: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -91,7 +83,6 @@ def maybe_convert_objects( convert_to_nullable_integer: Literal[True] = ..., dtype_if_all_nat: DtypeObj | None = ..., ) -> ArrayLike: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -105,7 +96,6 @@ def maybe_convert_objects( convert_to_nullable_integer: bool = ..., dtype_if_all_nat: DtypeObj | None = ..., ) -> ArrayLike: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -119,7 +109,6 @@ def maybe_convert_objects( convert_to_nullable_integer: bool = ..., dtype_if_all_nat: DtypeObj | None = ..., ) -> ArrayLike: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -133,7 +122,6 @@ def maybe_convert_objects( convert_to_nullable_integer: bool = ..., dtype_if_all_nat: DtypeObj | None = ..., ) -> ArrayLike: ... - @overload def maybe_convert_numeric( values: np.ndarray, # np.ndarray[object] @@ -142,7 +130,6 @@ def maybe_convert_numeric( coerce_numeric: bool = False, convert_to_masked_nullable: Literal[False] = ..., ) -> tuple[np.ndarray, None]: ... - @overload def maybe_convert_numeric( values: np.ndarray, # np.ndarray[object] @@ -161,50 +148,37 @@ def ensure_string_array( copy: bool = True, skipna: bool = True, ) -> np.ndarray: ... # np.ndarray[object] - def infer_datetimelike_array( - arr: np.ndarray # np.ndarray[object] + arr: np.ndarray, # np.ndarray[object] ) -> tuple[str, bool]: ... - def astype_intsafe( arr: np.ndarray, # np.ndarray[object] new_dtype: np.dtype, ) -> np.ndarray: ... - def fast_zip(ndarrays: list) -> np.ndarray: ... # np.ndarray[object] # TODO: can we be more specific about rows? def to_object_array_tuples(rows: object) -> ndarray_obj_2d: ... - def tuples_to_object_array( - tuples: np.ndarray # np.ndarray[object] + tuples: np.ndarray, # np.ndarray[object] ) -> ndarray_obj_2d: ... # TODO: can we be more specific about rows? def to_object_array(rows: object, min_width: int = 0) -> ndarray_obj_2d: ... - def dicts_to_array(dicts: list, columns: list) -> ndarray_obj_2d: ... - - def maybe_booleans_to_slice( - mask: np.ndarray # ndarray[uint8_t] + mask: np.ndarray, # ndarray[uint8_t] ) -> slice | np.ndarray: ... # np.ndarray[np.uint8] - def maybe_indices_to_slice( indices: np.ndarray, # np.ndarray[np.intp] max_len: int, ) -> slice | np.ndarray: ... # np.ndarray[np.uint8] - def is_all_arraylike(obj: list) -> bool: ... # ----------------------------------------------------------------- # Functions which in reality take memoryviews -def memory_usage_of_objects( - arr: np.ndarray # object[:] -) -> int: ... # np.int64 - - +def memory_usage_of_objects(arr: np.ndarray) -> int: ... # object[:] # np.int64 def map_infer_mask( arr: np.ndarray, f: Callable[[Any], Any], @@ -213,60 +187,39 @@ def map_infer_mask( na_value: Any = ..., dtype: np.dtype = ..., ) -> np.ndarray: ... - def indices_fast( - index: np.ndarray, # ndarray[intp_t] + index: np.ndarray, # ndarray[intp_t] labels: np.ndarray, # const int64_t[:] keys: list, sorted_labels: list[np.ndarray], # list[ndarray[np.int64]] ) -> dict: ... - def generate_slices( - labels: np.ndarray, # const intp_t[:] - ngroups: int -) -> tuple[ - np.ndarray, # np.ndarray[np.int64] - np.ndarray, # np.ndarray[np.int64] -]: ... - + labels: np.ndarray, ngroups: int # const intp_t[:] +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64] def count_level_2d( - mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True], + mask: np.ndarray, # ndarray[uint8_t, ndim=2, cast=True], labels: np.ndarray, # const intp_t[:] max_bin: int, - axis: int -) -> np.ndarray: ... # np.ndarray[np.int64, ndim=2] - + axis: int, +) -> np.ndarray: ... # np.ndarray[np.int64, ndim=2] def get_level_sorter( - label: np.ndarray, # const int64_t[:] + label: np.ndarray, # const int64_t[:] starts: np.ndarray, # const intp_t[:] -) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1] - - +) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1] def generate_bins_dt64( values: np.ndarray, # np.ndarray[np.int64] binner: np.ndarray, # const int64_t[:] closed: object = "left", hasnans: bool = False, -) -> np.ndarray: ... # np.ndarray[np.int64, ndim=1] - - +) -> np.ndarray: ... # np.ndarray[np.int64, ndim=1] def array_equivalent_object( - left: np.ndarray, # object[:] + left: np.ndarray, # object[:] right: np.ndarray, # object[:] ) -> bool: ... - -def has_infs_f8( - arr: np.ndarray # const float64_t[:] -) -> bool: ... - -def has_infs_f4( - arr: np.ndarray # const float32_t[:] -) -> bool: ... - +def has_infs_f8(arr: np.ndarray) -> bool: ... # const float64_t[:] +def has_infs_f4(arr: np.ndarray) -> bool: ... # const float32_t[:] def get_reverse_indexer( indexer: np.ndarray, # const intp_t[:] length: int, -) -> np.ndarray: ... # np.ndarray[np.intp] - - +) -> np.ndarray: ... # np.ndarray[np.intp] def is_bool_list(obj: list) -> bool: ... diff --git a/pandas/_libs/ops.pyi b/pandas/_libs/ops.pyi index 11d67dfb93d5f..d84b0dee20e7d 100644 --- a/pandas/_libs/ops.pyi +++ b/pandas/_libs/ops.pyi @@ -10,33 +10,26 @@ import numpy as np _BinOp = Callable[[Any, Any], Any] _BoolOp = Callable[[Any, Any], bool] - def scalar_compare( values: np.ndarray, # object[:] val: object, - op: _BoolOp, # {operator.eq, operator.ne, ...} -) -> np.ndarray: ... # np.ndarray[bool] - + op: _BoolOp, # {operator.eq, operator.ne, ...} +) -> np.ndarray: ... # np.ndarray[bool] def vec_compare( - left: np.ndarray, # np.ndarray[object] + left: np.ndarray, # np.ndarray[object] right: np.ndarray, # np.ndarray[object] - op: _BoolOp, # {operator.eq, operator.ne, ...} -) -> np.ndarray: ... # np.ndarray[bool] - - + op: _BoolOp, # {operator.eq, operator.ne, ...} +) -> np.ndarray: ... # np.ndarray[bool] def scalar_binop( - values: np.ndarray, # object[:] + values: np.ndarray, # object[:] val: object, - op: _BinOp, # binary operator + op: _BinOp, # binary operator ) -> np.ndarray: ... - - def vec_binop( - left: np.ndarray, # object[:] + left: np.ndarray, # object[:] right: np.ndarray, # object[:] - op: _BinOp, # binary operator + op: _BinOp, # binary operator ) -> np.ndarray: ... - @overload def maybe_convert_bool( arr: np.ndarray, # np.ndarray[object] @@ -44,7 +37,6 @@ def maybe_convert_bool( false_values=..., convert_to_masked_nullable: Literal[False] = ..., ) -> tuple[np.ndarray, None]: ... - @overload def maybe_convert_bool( arr: np.ndarray, # np.ndarray[object] diff --git a/pandas/_libs/parsers.pyi b/pandas/_libs/parsers.pyi index 92b970d47467e..9ff05adceb2b4 100644 --- a/pandas/_libs/parsers.pyi +++ b/pandas/_libs/parsers.pyi @@ -12,20 +12,17 @@ from pandas._typing import ( STR_NA_VALUES: set[str] - def sanitize_objects( values: np.ndarray, # ndarray[object] na_values: set, convert_empty: bool = ..., ) -> int: ... - class TextReader: unnamed_cols: set[str] - table_width: int # int64_t + table_width: int # int64_t leading_cols: int # int64_t header: list[list[int]] # non-negative integers - def __init__( self, source, @@ -64,14 +61,11 @@ class TextReader: mangle_dupe_cols: bool = ..., float_precision: Literal["round_trip", "legacy", "high"] | None = ..., skip_blank_lines: bool = ..., - encoding_errors: bytes | str = ... + encoding_errors: bytes | str = ..., ): ... - def set_error_bad_lines(self, status: int) -> None: ... def set_noconvert(self, i: int) -> None: ... def remove_noconvert(self, i: int) -> None: ... - def close(self) -> None: ... - def read(self, rows: int | None = ...) -> dict[int, ArrayLike]: ... def read_low_memory(self, rows: int | None) -> list[dict[int, ArrayLike]]: ... diff --git a/pandas/_libs/reshape.pyi b/pandas/_libs/reshape.pyi index 7aaa18a7feff2..0457ceb1e03e6 100644 --- a/pandas/_libs/reshape.pyi +++ b/pandas/_libs/reshape.pyi @@ -1,19 +1,14 @@ import numpy as np def unstack( - values: np.ndarray, # reshape_t[:, :] - mask: np.ndarray, # const uint8_t[:] + values: np.ndarray, # reshape_t[:, :] + mask: np.ndarray, # const uint8_t[:] stride: int, length: int, width: int, new_values: np.ndarray, # reshape_t[:, :] - new_mask: np.ndarray, # uint8_t[:, :] + new_mask: np.ndarray, # uint8_t[:, :] ) -> None: ... - - def explode( values: np.ndarray, # np.ndarray[object] -) -> tuple[ - np.ndarray, # np.ndarray[object] - np.ndarray, # np.ndarray[np.int64] -]: ... +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[object] # np.ndarray[np.int64] diff --git a/pandas/_libs/testing.pyi b/pandas/_libs/testing.pyi index ac0c772780c5c..01da496975f51 100644 --- a/pandas/_libs/testing.pyi +++ b/pandas/_libs/testing.pyi @@ -1,8 +1,12 @@ - - def assert_dict_equal(a, b, compare_keys: bool = ...): ... - -def assert_almost_equal(a, b, - rtol: float = ..., atol: float = ..., - check_dtype: bool = ..., - obj=..., lobj=..., robj=..., index_values=...): ... +def assert_almost_equal( + a, + b, + rtol: float = ..., + atol: float = ..., + check_dtype: bool = ..., + obj=..., + lobj=..., + robj=..., + index_values=..., +): ... diff --git a/pandas/_libs/tslib.pyi b/pandas/_libs/tslib.pyi index 641e62e7c8973..f43a81f20700a 100644 --- a/pandas/_libs/tslib.pyi +++ b/pandas/_libs/tslib.pyi @@ -3,20 +3,16 @@ from datetime import tzinfo import numpy as np def format_array_from_datetime( - values: np.ndarray, # np.ndarray[np.int64] + values: np.ndarray, # np.ndarray[np.int64] tz: tzinfo | None = ..., format: str | None = ..., - na_rep: object = ... + na_rep: object = ..., ) -> np.ndarray: ... # np.ndarray[object] - - def array_with_unit_to_datetime( values: np.ndarray, unit: str, errors: str = ..., ) -> tuple[np.ndarray, tzinfo | None]: ... - - def array_to_datetime( values: np.ndarray, # np.ndarray[object] errors: str = ..., @@ -26,4 +22,5 @@ def array_to_datetime( require_iso8601: bool = ..., allow_mixed: bool = ..., ) -> tuple[np.ndarray, tzinfo | None]: ... + # returned ndarray may be object dtype or datetime64[ns] diff --git a/pandas/_libs/tslibs/ccalendar.pyi b/pandas/_libs/tslibs/ccalendar.pyi index 500a0423bc9cf..993f18a61d74a 100644 --- a/pandas/_libs/tslibs/ccalendar.pyi +++ b/pandas/_libs/tslibs/ccalendar.pyi @@ -1,4 +1,3 @@ - DAYS: list[str] MONTH_ALIASES: dict[int, str] MONTH_NUMBERS: dict[str, int] diff --git a/pandas/_libs/tslibs/conversion.pyi b/pandas/_libs/tslibs/conversion.pyi index 6470361542597..e74a56a519c5a 100644 --- a/pandas/_libs/tslibs/conversion.pyi +++ b/pandas/_libs/tslibs/conversion.pyi @@ -12,30 +12,16 @@ class OutOfBoundsTimedelta(ValueError): ... def precision_from_unit( unit: str, -) -> tuple[ - int, # int64_t - int, -]: ... - - +) -> tuple[int, int,]: ... # (int64_t, _) def ensure_datetime64ns( arr: np.ndarray, # np.ndarray[datetime64[ANY]] copy: bool = ..., ) -> np.ndarray: ... # np.ndarray[datetime64ns] - - def ensure_timedelta64ns( arr: np.ndarray, # np.ndarray[timedelta64[ANY]] copy: bool = ..., ) -> np.ndarray: ... # np.ndarray[timedelta64ns] - - def datetime_to_datetime64( values: np.ndarray, # np.ndarray[object] -) -> tuple[ - np.ndarray, # np.ndarray[dt64ns] - tzinfo | None, -]: ... - - +) -> tuple[np.ndarray, tzinfo | None,]: ... # (np.ndarray[dt64ns], _) def localize_pydatetime(dt: datetime, tz: tzinfo | None) -> datetime: ... diff --git a/pandas/_libs/tslibs/dtypes.pyi b/pandas/_libs/tslibs/dtypes.pyi index d3aea5b0be796..f6a8d7887ced1 100644 --- a/pandas/_libs/tslibs/dtypes.pyi +++ b/pandas/_libs/tslibs/dtypes.pyi @@ -5,20 +5,16 @@ from pandas._libs.tslibs.offsets import BaseOffset _attrname_to_abbrevs: dict[str, str] _period_code_map: dict[str, int] - class PeriodDtypeBase: _dtype_code: int # PeriodDtypeCode # actually __cinit__ def __new__(self, code: int): ... - def freq_group_code(self) -> int: ... def date_offset(self) -> BaseOffset: ... - @classmethod def from_date_offset(cls, offset: BaseOffset) -> PeriodDtypeBase: ... - class FreqGroup(Enum): FR_ANN: int = ... FR_QTR: int = ... @@ -33,11 +29,9 @@ class FreqGroup(Enum): FR_US: int = ... FR_NS: int = ... FR_UND: int = ... - @staticmethod def get_freq_group(code: int) -> FreqGroup: ... - class Resolution(Enum): RESO_NS: int = ... RESO_US: int = ... @@ -49,19 +43,13 @@ class Resolution(Enum): RESO_MTH: int = ... RESO_QTR: int = ... RESO_YR: int = ... - def __lt__(self, other: Resolution) -> bool: ... - def __ge__(self, other: Resolution) -> bool: ... - @property def freq_group(self) -> FreqGroup: ... - @property def attrname(self) -> str: ... - @classmethod def from_attrname(cls, attrname: str) -> Resolution: ... - @classmethod def get_reso_from_freq(cls, freq: str) -> Resolution: ... diff --git a/pandas/_libs/tslibs/fields.pyi b/pandas/_libs/tslibs/fields.pyi index 22ae156d78b7d..244af38e25da0 100644 --- a/pandas/_libs/tslibs/fields.pyi +++ b/pandas/_libs/tslibs/fields.pyi @@ -3,67 +3,48 @@ import numpy as np def build_field_sarray( dtindex: np.ndarray, # const int64_t[:] ) -> np.ndarray: ... - def month_position_check(fields, weekdays) -> str | None: ... - def get_date_name_field( dtindex: np.ndarray, # const int64_t[:] field: str, locale=..., ) -> np.ndarray: ... # np.ndarray[object] - def get_start_end_field( dtindex: np.ndarray, # const int64_t[:] field: str, freqstr: str | None = ..., - month_kw: int = ... + month_kw: int = ..., ) -> np.ndarray: ... # np.ndarray[bool] - - def get_date_field( dtindex: np.ndarray, # const int64_t[:] - field: str, ) -> np.ndarray: ... # np.ndarray[in32] - - def get_timedelta_field( tdindex: np.ndarray, # const int64_t[:] field: str, ) -> np.ndarray: ... # np.ndarray[int32] - - def isleapyear_arr( years: np.ndarray, ) -> np.ndarray: ... # np.ndarray[bool] - def build_isocalendar_sarray( dtindex: np.ndarray, # const int64_t[:] ) -> np.ndarray: ... - - def get_locale_names(name_type: str, locale: object = None): ... - class RoundTo: @property def MINUS_INFTY(self) -> int: ... - @property def PLUS_INFTY(self) -> int: ... - @property def NEAREST_HALF_EVEN(self) -> int: ... - @property def NEAREST_HALF_PLUS_INFTY(self) -> int: ... - @property def NEAREST_HALF_MINUS_INFTY(self) -> int: ... - def round_nsint64( - values: np.ndarray, # np.ndarray[np.int64] + values: np.ndarray, # np.ndarray[np.int64] mode: RoundTo, nanos: int, ) -> np.ndarray: ... # np.ndarray[np.int64] diff --git a/pandas/_libs/tslibs/nattype.pyi b/pandas/_libs/tslibs/nattype.pyi index 5a2985d0e815b..22e6395a1fe99 100644 --- a/pandas/_libs/tslibs/nattype.pyi +++ b/pandas/_libs/tslibs/nattype.pyi @@ -1,4 +1,3 @@ - from datetime import ( datetime, timedelta, @@ -17,11 +16,9 @@ def is_null_datetimelike(val: object, inat_is_null: bool = ...) -> bool: ... class NaTType(datetime): value: np.int64 - def asm8(self) -> np.datetime64: ... def to_datetime64(self) -> np.datetime64: ... def to_numpy(self, dtype=..., copy: bool = ...) -> np.datetime64: ... - @property def is_leap_year(self) -> bool: ... @property @@ -36,7 +33,6 @@ class NaTType(datetime): def is_quarter_end(self) -> bool: ... @property def is_year_end(self) -> bool: ... - @property def day_of_year(self) -> float: ... @property @@ -53,81 +49,61 @@ class NaTType(datetime): def week(self) -> float: ... @property def weekofyear(self) -> float: ... - def day_name(self) -> float: ... def month_name(self) -> float: ... - # error: Return type "float" of "weekday" incompatible with return # type "int" in supertype "date" def weekday(self) -> float: ... # type: ignore[override] - # error: Return type "float" of "isoweekday" incompatible with return # type "int" in supertype "date" def isoweekday(self) -> float: ... # type: ignore[override] - def total_seconds(self) -> float: ... - # error: Signature of "today" incompatible with supertype "datetime" def today(self, *args, **kwargs) -> NaTType: ... # type: ignore[override] # error: Signature of "today" incompatible with supertype "datetime" def now(self, *args, **kwargs) -> NaTType: ... # type: ignore[override] - def to_pydatetime(self) -> NaTType: ... def date(self) -> NaTType: ... - def round(self) -> NaTType: ... def floor(self) -> NaTType: ... def ceil(self) -> NaTType: ... - def tz_convert(self) -> NaTType: ... def tz_localize(self) -> NaTType: ... - def replace(self, *args, **kwargs) -> NaTType: ... - # error: Return type "float" of "year" incompatible with return # type "int" in supertype "date" @property def year(self) -> float: ... # type: ignore[override] - @property def quarter(self) -> float: ... - # error: Return type "float" of "month" incompatible with return # type "int" in supertype "date" @property def month(self) -> float: ... # type: ignore[override] - # error: Return type "float" of "day" incompatible with return # type "int" in supertype "date" @property def day(self) -> float: ... # type: ignore[override] - # error: Return type "float" of "hour" incompatible with return # type "int" in supertype "date" @property def hour(self) -> float: ... # type: ignore[override] - # error: Return type "float" of "minute" incompatible with return # type "int" in supertype "date" @property def minute(self) -> float: ... # type: ignore[override] - # error: Return type "float" of "second" incompatible with return # type "int" in supertype "date" @property def second(self) -> float: ... # type: ignore[override] - @property def millisecond(self) -> float: ... - # error: Return type "float" of "microsecond" incompatible with return # type "int" in supertype "date" @property def microsecond(self) -> float: ... # type: ignore[override] - @property def nanosecond(self) -> float: ... - # inject Timedelta properties @property def days(self) -> float: ... @@ -135,35 +111,29 @@ class NaTType(datetime): def microseconds(self) -> float: ... @property def nanoseconds(self) -> float: ... - # inject Period properties @property def qyear(self) -> float: ... - def __eq__(self, other: Any) -> bool: ... def __ne__(self, other: Any) -> bool: ... # https://github.com/python/mypy/issues/9015 # error: Argument 1 of "__lt__" is incompatible with supertype "date"; # supertype defines the argument type as "date" def __lt__( # type: ignore[override] - self, - other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 + self, other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 ) -> bool: ... # error: Argument 1 of "__le__" is incompatible with supertype "date"; # supertype defines the argument type as "date" def __le__( # type: ignore[override] - self, - other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 + self, other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 ) -> bool: ... # error: Argument 1 of "__gt__" is incompatible with supertype "date"; # supertype defines the argument type as "date" def __gt__( # type: ignore[override] - self, - other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 + self, other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 ) -> bool: ... # error: Argument 1 of "__ge__" is incompatible with supertype "date"; # supertype defines the argument type as "date" def __ge__( # type: ignore[override] - self, - other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 + self, other: datetime | timedelta | Period | np.datetime64 | np.timedelta64 ) -> bool: ... diff --git a/pandas/_libs/tslibs/parsing.pyi b/pandas/_libs/tslibs/parsing.pyi index f346204d69d25..fc08a48cee343 100644 --- a/pandas/_libs/tslibs/parsing.pyi +++ b/pandas/_libs/tslibs/parsing.pyi @@ -6,35 +6,26 @@ from pandas._libs.tslibs.offsets import BaseOffset class DateParseError(ValueError): ... - def parse_datetime_string( date_string: str, dayfirst: bool = ..., yearfirst: bool = ..., **kwargs, ) -> datetime: ... - - def parse_time_string( arg: str, freq: BaseOffset | str | None = ..., dayfirst: bool | None = ..., yearfirst: bool | None = ..., ) -> tuple[datetime, str]: ... - - def _does_string_look_like_datetime(py_string: str) -> bool: ... - def quarter_to_myear(year: int, quarter: int, freq: str) -> tuple[int, int]: ... - - def try_parse_dates( values: np.ndarray, # object[:] parser=..., dayfirst: bool = ..., default: datetime | None = ..., ) -> np.ndarray: ... # np.ndarray[object] - def try_parse_date_and_time( dates: np.ndarray, # object[:] times: np.ndarray, # object[:] @@ -42,40 +33,29 @@ def try_parse_date_and_time( time_parser=..., dayfirst: bool = ..., default: datetime | None = ..., -) -> np.ndarray: ... # np.ndarray[object] - +) -> np.ndarray: ... # np.ndarray[object] def try_parse_year_month_day( years: np.ndarray, # object[:] - months: np.ndarray, # object[:] - days: np.ndarray, # object[:] -) -> np.ndarray: ... # np.ndarray[object] - - + months: np.ndarray, # object[:] + days: np.ndarray, # object[:] +) -> np.ndarray: ... # np.ndarray[object] def try_parse_datetime_components( - years: np.ndarray, # object[:] + years: np.ndarray, # object[:] months: np.ndarray, # object[:] - days: np.ndarray, # object[:] - hours: np.ndarray, # object[:] - minutes: np.ndarray, # object[:] - seconds: np.ndarray, # object[:] -) -> np.ndarray: ... # np.ndarray[object] - - + days: np.ndarray, # object[:] + hours: np.ndarray, # object[:] + minutes: np.ndarray, # object[:] + seconds: np.ndarray, # object[:] +) -> np.ndarray: ... # np.ndarray[object] def format_is_iso(f: str) -> bool: ... - - def guess_datetime_format( dt_str, dayfirst: bool = ..., dt_str_parse=..., dt_str_split=..., ) -> str | None: ... - - def concat_date_cols( date_cols: tuple, keep_trivial_numbers: bool = ..., ) -> np.ndarray: ... # np.ndarray[object] - - def get_rule_month(source: str) -> str: ... diff --git a/pandas/_libs/tslibs/period.pyi b/pandas/_libs/tslibs/period.pyi index 49e630d605310..97738d51b5a0e 100644 --- a/pandas/_libs/tslibs/period.pyi +++ b/pandas/_libs/tslibs/period.pyi @@ -19,41 +19,34 @@ def periodarr_to_dt64arr( periodarr: np.ndarray, # const int64_t[:] freq: int, ) -> np.ndarray: ... # np.ndarray[np.int64] - def period_asfreq_arr( arr: np.ndarray, # ndarray[int64_t] arr, freq1: int, freq2: int, end: bool, -) -> np.ndarray: ... # np.ndarray[np.int64] - +) -> np.ndarray: ... # np.ndarray[np.int64] def get_period_field_arr( field: str, arr: np.ndarray, # const int64_t[:] freq: int, -) -> np.ndarray: ... # np.ndarray[np.int64] - +) -> np.ndarray: ... # np.ndarray[np.int64] def from_ordinals( values: np.ndarray, # const int64_t[:] freq: Frequency, ) -> np.ndarray: ... # np.ndarray[np.int64] - def extract_ordinals( values: np.ndarray, # np.ndarray[object] freq: Frequency | int, ) -> np.ndarray: ... # np.ndarray[np.int64] - def extract_freq( values: np.ndarray, # np.ndarray[object] ) -> BaseOffset: ... # exposed for tests def period_asfreq(ordinal: int, freq1: int, freq2: int, end: bool) -> int: ... - def period_ordinal( y: int, m: int, d: int, h: int, min: int, s: int, us: int, ps: int, freq: int ) -> int: ... - def freq_to_dtype_code(freq: BaseOffset) -> int: ... def validate_end_alias(how: str) -> Literal["E", "S"]: ... @@ -75,84 +68,57 @@ class Period: minute=None, second=None, ) -> Period | NaTType: ... - @classmethod def _maybe_convert_freq(cls, freq) -> BaseOffset: ... - @classmethod def _from_ordinal(cls, ordinal: int, freq) -> Period: ... - @classmethod def now(cls, freq=...) -> Period: ... - def strftime(self, fmt: str) -> str: ... - def to_timestamp( self, - freq: str | BaseOffset | None =..., + freq: str | BaseOffset | None = ..., how: str = ..., tz: Timezone | None = ..., ) -> Timestamp: ... - def asfreq(self, freq, how=...) -> Period: ... - @property def freqstr(self) -> str: ... - @property def is_leap_year(self) -> bool: ... - @property def daysinmonth(self) -> int: ... - @property def days_in_month(self) -> int: ... - @property def qyear(self) -> int: ... - @property def quarter(self) -> int: ... - @property def day_of_year(self) -> int: ... - @property def weekday(self) -> int: ... - @property def day_of_week(self) -> int: ... - @property def week(self) -> int: ... - @property def weekofyear(self) -> int: ... - @property def second(self) -> int: ... - @property def minute(self) -> int: ... - @property def hour(self) -> int: ... - @property def day(self) -> int: ... - @property def month(self) -> int: ... - @property def year(self) -> int: ... - @property def end_time(self) -> Timestamp: ... - @property def start_time(self) -> Timestamp: ... - def __sub__(self, other) -> Period | BaseOffset: ... - def __add__(self, other) -> Period: ... diff --git a/pandas/_libs/tslibs/timedeltas.pyi b/pandas/_libs/tslibs/timedeltas.pyi index 9ccc3a8ed5fa4..31a836b2c2079 100644 --- a/pandas/_libs/tslibs/timedeltas.pyi +++ b/pandas/_libs/tslibs/timedeltas.pyi @@ -15,26 +15,18 @@ from pandas._libs.tslibs import ( _S = TypeVar("_S") - def ints_to_pytimedelta( arr: np.ndarray, # const int64_t[:] box: bool = ..., ) -> np.ndarray: ... # np.ndarray[object] - - def array_to_timedelta64( values: np.ndarray, # ndarray[object] unit: str | None = ..., errors: str = ..., ) -> np.ndarray: ... # np.ndarray[m8ns] - - def parse_timedelta_unit(unit: str | None) -> str: ... - - def delta_to_nanoseconds(delta: Tick | np.timedelta64 | timedelta | int) -> int: ... - class Timedelta(timedelta): min: ClassVar[Timedelta] max: ClassVar[Timedelta] @@ -43,12 +35,8 @@ class Timedelta(timedelta): # error: "__new__" must return a class instance (got "Union[Timedelta, NaTType]") def __new__( # type: ignore[misc] - cls: Type[_S], - value=..., - unit=..., - **kwargs + cls: Type[_S], value=..., unit=..., **kwargs ) -> _S | NaTType: ... - @property def days(self) -> int: ... @property @@ -56,21 +44,16 @@ class Timedelta(timedelta): @property def microseconds(self) -> int: ... def total_seconds(self) -> float: ... - def to_pytimedelta(self) -> timedelta: ... def to_timedelta64(self) -> np.timedelta64: ... - @property def asm8(self) -> np.timedelta64: ... - # TODO: round/floor/ceil could return NaT? def round(self: _S, freq) -> _S: ... def floor(self: _S, freq) -> _S: ... def ceil(self: _S, freq) -> _S: ... - @property def resolution_string(self) -> str: ... - def __add__(self, other: timedelta) -> timedelta: ... def __radd__(self, other: timedelta) -> timedelta: ... def __sub__(self, other: timedelta) -> timedelta: ... @@ -80,19 +63,16 @@ class Timedelta(timedelta): def __abs__(self) -> timedelta: ... def __mul__(self, other: float) -> timedelta: ... def __rmul__(self, other: float) -> timedelta: ... - @overload def __floordiv__(self, other: timedelta) -> int: ... @overload def __floordiv__(self, other: int) -> timedelta: ... - @overload def __truediv__(self, other: timedelta) -> float: ... @overload def __truediv__(self, other: float) -> timedelta: ... def __mod__(self, other: timedelta) -> timedelta: ... def __divmod__(self, other: timedelta) -> tuple[int, timedelta]: ... - def __le__(self, other: timedelta) -> bool: ... def __lt__(self, other: timedelta) -> bool: ... def __ge__(self, other: timedelta) -> bool: ... diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 5a9346bb75721..ff6b18835322e 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -60,9 +60,7 @@ class Timestamp(datetime): *, fold: int | None = ..., ) -> _S | NaTType: ... - def _set_freq(self, freq: BaseOffset | None) -> None: ... - @property def year(self) -> int: ... @property diff --git a/pandas/_libs/window/aggregations.pyi b/pandas/_libs/window/aggregations.pyi index 3391edac84224..fe083fe415e4b 100644 --- a/pandas/_libs/window/aggregations.pyi +++ b/pandas/_libs/window/aggregations.pyi @@ -11,58 +11,50 @@ def roll_sum( start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t -) -> np.ndarray: ... # np.ndarray[float] - +) -> np.ndarray: ... # np.ndarray[float] def roll_mean( values: np.ndarray, # const float64_t[:] start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t -) -> np.ndarray: ... # np.ndarray[float] - +) -> np.ndarray: ... # np.ndarray[float] def roll_var( values: np.ndarray, # const float64_t[:] start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t ddof: int = ..., -) -> np.ndarray: ... # np.ndarray[float] - +) -> np.ndarray: ... # np.ndarray[float] def roll_skew( values: np.ndarray, # np.ndarray[np.float64] start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t -) -> np.ndarray: ... # np.ndarray[float] - +) -> np.ndarray: ... # np.ndarray[float] def roll_kurt( values: np.ndarray, # np.ndarray[np.float64] start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t -) -> np.ndarray: ... # np.ndarray[float] - +) -> np.ndarray: ... # np.ndarray[float] def roll_median_c( values: np.ndarray, # np.ndarray[np.float64] start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t ) -> np.ndarray: ... # np.ndarray[float] - def roll_max( values: np.ndarray, # np.ndarray[np.float64] start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t ) -> np.ndarray: ... # np.ndarray[float] - def roll_min( values: np.ndarray, # np.ndarray[np.float64] start: np.ndarray, # np.ndarray[np.int64] end: np.ndarray, # np.ndarray[np.int64] minp: int, # int64_t ) -> np.ndarray: ... # np.ndarray[float] - def roll_quantile( values: np.ndarray, # const float64_t[:] start: np.ndarray, # np.ndarray[np.int64] @@ -71,7 +63,6 @@ def roll_quantile( quantile: float, # float64_t interpolation: Literal["linear", "lower", "higher", "nearest", "midpoint"], ) -> np.ndarray: ... # np.ndarray[float] - def roll_apply( obj: object, start: np.ndarray, # np.ndarray[np.int64] @@ -82,26 +73,22 @@ def roll_apply( args: tuple[Any, ...], kwargs: dict[str, Any], ) -> np.ndarray: ... # np.ndarray[float] # FIXME: could also be type(obj) if n==0 - def roll_weighted_sum( values: np.ndarray, # const float64_t[:] weights: np.ndarray, # const float64_t[:] minp: int, ) -> np.ndarray: ... # np.ndarray[np.float64] - def roll_weighted_mean( values: np.ndarray, # const float64_t[:] weights: np.ndarray, # const float64_t[:] minp: int, ) -> np.ndarray: ... # np.ndarray[np.float64] - def roll_weighted_var( values: np.ndarray, # const float64_t[:] weights: np.ndarray, # const float64_t[:] minp: int, # int64_t ddof: int, # unsigned int ) -> np.ndarray: ... # np.ndarray[np.float64] - def ewma( vals: np.ndarray, # const float64_t[:] start: np.ndarray, # const int64_t[:] @@ -112,7 +99,6 @@ def ewma( ignore_na: bool, deltas: np.ndarray, # const float64_t[:] ) -> np.ndarray: ... # np.ndarray[np.float64] - def ewmcov( input_x: np.ndarray, # const float64_t[:] start: np.ndarray, # const int64_t[:] diff --git a/pandas/_libs/window/indexers.pyi b/pandas/_libs/window/indexers.pyi index a32fe2f0f8b03..2dea9362228e5 100644 --- a/pandas/_libs/window/indexers.pyi +++ b/pandas/_libs/window/indexers.pyi @@ -1,13 +1,10 @@ import numpy as np def calculate_variable_window_bounds( - num_values: int, # int64_t - window_size: int, # int64_t + num_values: int, # int64_t + window_size: int, # int64_t min_periods, center: bool, closed: str | None, index: np.ndarray, # const int64_t[:] -) -> tuple[ - np.ndarray, # np.ndarray[np.int64] - np.ndarray, # np.ndarray[np.int64] -]: ... +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64] diff --git a/pandas/_libs/writers.pyi b/pandas/_libs/writers.pyi index 67f6059c2a825..c188dc2bd9048 100644 --- a/pandas/_libs/writers.pyi +++ b/pandas/_libs/writers.pyi @@ -8,15 +8,11 @@ def write_csv_rows( cols: np.ndarray, writer: object, # _csv.writer ) -> None: ... - def convert_json_to_lines(arr: str) -> str: ... - def max_len_string_array( arr: np.ndarray, # pandas_string[:] ) -> int: ... - def word_len(val: object) -> int: ... - def string_array_replace_from_nan_rep( arr: np.ndarray, # np.ndarray[object, ndim=1] nan_rep: object, diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 40f23c25a1e99..fc6c7f4c17ea0 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -278,7 +278,7 @@ def makeUnicodeIndex(k=10, name=None): def makeCategoricalIndex(k=10, n=3, name=None, **kwargs): - """ make a length k index or n categories """ + """make a length k index or n categories""" x = rands_array(nchars=4, size=n) return CategoricalIndex( Categorical.from_codes(np.arange(k) % n, categories=x), name=name, **kwargs @@ -286,7 +286,7 @@ def makeCategoricalIndex(k=10, n=3, name=None, **kwargs): def makeIntervalIndex(k=10, name=None, **kwargs): - """ make a length k IntervalIndex """ + """make a length k IntervalIndex""" x = np.linspace(0, 100, num=(k + 1)) return IntervalIndex.from_breaks(x, name=name, **kwargs) diff --git a/pandas/conftest.py b/pandas/conftest.py index e106f7f425fa0..218fae7ecd969 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -580,7 +580,7 @@ def datetime_series(): def _create_series(index): - """ Helper for the _series dict """ + """Helper for the _series dict""" size = len(index) data = np.random.randn(size) return Series(data, index=index, name="a") diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 47404ae129254..177dfee0c03ab 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1838,7 +1838,7 @@ def safe_sort( def _sort_mixed(values) -> np.ndarray: - """ order ints before strings in 1d arrays, safe in py3 """ + """order ints before strings in 1d arrays, safe in py3""" str_pos = np.array([isinstance(x, str) for x in values], dtype=bool) nums = np.sort(values[~str_pos]) strs = np.sort(values[str_pos]) diff --git a/pandas/core/apply.py b/pandas/core/apply.py index 00b49c2f4f951..388c1881afed7 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -77,7 +77,7 @@ def frame_apply( args=None, kwargs=None, ) -> FrameApply: - """ construct and return a row or column based frame apply object """ + """construct and return a row or column based frame apply object""" axis = obj._get_axis_number(axis) klass: type[FrameApply] if axis == 0: @@ -639,7 +639,7 @@ def dtypes(self) -> Series: return self.obj.dtypes def apply(self) -> FrameOrSeriesUnion: - """ compute the results """ + """compute the results""" # dispatch to agg if is_list_like(self.f): return self.apply_multiple() @@ -733,7 +733,7 @@ def apply_empty_result(self): return self.obj.copy() def apply_raw(self): - """ apply to the values as a numpy array """ + """apply to the values as a numpy array""" def wrap_function(func): """ @@ -867,7 +867,7 @@ def result_columns(self) -> Index: def wrap_results_for_axis( self, results: ResType, res_index: Index ) -> FrameOrSeriesUnion: - """ return the results for the rows """ + """return the results for the rows""" if self.result_type == "reduce": # e.g. test_apply_dict GH#8735 @@ -950,7 +950,7 @@ def result_columns(self) -> Index: def wrap_results_for_axis( self, results: ResType, res_index: Index ) -> FrameOrSeriesUnion: - """ return the results for the columns """ + """return the results for the columns""" result: FrameOrSeriesUnion # we have requested to expand @@ -969,7 +969,7 @@ def wrap_results_for_axis( return result def infer_to_same_shape(self, results: ResType, res_index: Index) -> DataFrame: - """ infer the results to the same shape as the input object """ + """infer the results to the same shape as the input object""" result = self.obj._constructor(data=results) result = result.T diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 5fdfaf9ff0c7f..34e80baa2082c 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1636,7 +1636,7 @@ def _internal_get_values(self): return np.array(self) def check_for_ordered(self, op): - """ assert that we are ordered """ + """assert that we are ordered""" if not self.ordered: raise TypeError( f"Categorical is not ordered for operation {op}\n" diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 11f9f645920ec..d274501143916 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -78,7 +78,7 @@ class BaseMaskedDtype(ExtensionDtype): @cache_readonly def numpy_dtype(self) -> np.dtype: - """ Return an instance of our numpy dtype """ + """Return an instance of our numpy dtype""" return np.dtype(self.type) @cache_readonly @@ -87,7 +87,7 @@ def kind(self) -> str: @cache_readonly def itemsize(self) -> int: - """ Return the number of bytes in this dtype """ + """Return the number of bytes in this dtype""" return self.numpy_dtype.itemsize @classmethod diff --git a/pandas/core/arrays/sparse/scipy_sparse.py b/pandas/core/arrays/sparse/scipy_sparse.py index ad2c5f75fc32c..7ebda1f17ba56 100644 --- a/pandas/core/arrays/sparse/scipy_sparse.py +++ b/pandas/core/arrays/sparse/scipy_sparse.py @@ -34,7 +34,7 @@ def _to_ijv(ss, row_levels=(0,), column_levels=(1,), sort_labels=False): nonnull_labels = ss.dropna() def get_indexers(levels): - """ Return sparse coords and dense labels for subset levels """ + """Return sparse coords and dense labels for subset levels""" # TODO: how to do this better? cleanly slice nonnull_labels given the # coord values_ilabels = [tuple(x[i] for i in levels) for x in nonnull_labels.index] diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index 5fc2b6bceaada..d495f89970348 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -564,7 +564,7 @@ def visit_List(self, node, **kwargs): visit_Tuple = visit_List def visit_Index(self, node, **kwargs): - """ df.index[4] """ + """df.index[4]""" return self.visit(node.value) def visit_Subscript(self, node, **kwargs): @@ -588,7 +588,7 @@ def visit_Subscript(self, node, **kwargs): return self.term_type(name, env=self.env) def visit_Slice(self, node, **kwargs): - """ df.index[slice(4,6)] """ + """df.index[slice(4,6)]""" lower = node.lower if lower is not None: lower = self.visit(lower).value diff --git a/pandas/core/computation/expressions.py b/pandas/core/computation/expressions.py index 789e10d1de05d..a62137bd63692 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -70,7 +70,7 @@ def _evaluate_standard(op, op_str, a, b): def _can_use_numexpr(op, op_str, a, b, dtype_check): - """ return a boolean if we WILL be using numexpr """ + """return a boolean if we WILL be using numexpr""" if op_str is not None: # required min elements (otherwise we are adding overhead) diff --git a/pandas/core/computation/pytables.py b/pandas/core/computation/pytables.py index 0e6a7551ab399..f733a5c43dfb3 100644 --- a/pandas/core/computation/pytables.py +++ b/pandas/core/computation/pytables.py @@ -113,7 +113,7 @@ def _disallow_scalar_only_bool_ops(self): def prune(self, klass): def pr(left, right): - """ create and return a new specialized BinOp from myself """ + """create and return a new specialized BinOp from myself""" if left is None: return right elif right is None: @@ -154,7 +154,7 @@ def pr(left, right): return res def conform(self, rhs): - """ inplace conform rhs """ + """inplace conform rhs""" if not is_list_like(rhs): rhs = [rhs] if isinstance(rhs, np.ndarray): @@ -163,7 +163,7 @@ def conform(self, rhs): @property def is_valid(self) -> bool: - """ return True if this is a valid field """ + """return True if this is a valid field""" return self.lhs in self.queryables @property @@ -176,21 +176,21 @@ def is_in_table(self) -> bool: @property def kind(self): - """ the kind of my field """ + """the kind of my field""" return getattr(self.queryables.get(self.lhs), "kind", None) @property def meta(self): - """ the meta of my field """ + """the meta of my field""" return getattr(self.queryables.get(self.lhs), "meta", None) @property def metadata(self): - """ the metadata of my field """ + """the metadata of my field""" return getattr(self.queryables.get(self.lhs), "metadata", None) def generate(self, v) -> str: - """ create and return the op string for this TermValue """ + """create and return the op string for this TermValue""" val = v.tostring(self.encoding) return f"({self.lhs} {self.op} {val})" @@ -273,7 +273,7 @@ def __repr__(self) -> str: return pprint_thing(f"[Filter : [{self.filter[0]}] -> [{self.filter[1]}]") def invert(self): - """ invert the filter """ + """invert the filter""" if self.filter is not None: self.filter = ( self.filter[0], @@ -283,7 +283,7 @@ def invert(self): return self def format(self): - """ return the actual filter format """ + """return the actual filter format""" return [self.filter] def evaluate(self): @@ -338,7 +338,7 @@ def __repr__(self) -> str: return pprint_thing(f"[Condition : [{self.condition}]]") def invert(self): - """ invert the condition """ + """invert the condition""" # if self.condition is not None: # self.condition = "~(%s)" % self.condition # return self @@ -347,7 +347,7 @@ def invert(self): ) def format(self): - """ return the actual ne format """ + """return the actual ne format""" return self.condition def evaluate(self): @@ -604,7 +604,7 @@ def __repr__(self) -> str: return pprint_thing(self.expr) def evaluate(self): - """ create and return the numexpr condition and filter """ + """create and return the numexpr condition and filter""" try: self.condition = self.terms.prune(ConditionBinOp) except AttributeError as err: @@ -624,7 +624,7 @@ def evaluate(self): class TermValue: - """ hold a term value the we use to construct a condition/filter """ + """hold a term value the we use to construct a condition/filter""" def __init__(self, value, converted, kind: str): assert isinstance(kind, str), kind @@ -633,7 +633,7 @@ def __init__(self, value, converted, kind: str): self.kind = kind def tostring(self, encoding) -> str: - """ quote the string if not encoded else encode and return """ + """quote the string if not encoded else encode and return""" if self.kind == "string": if encoding is not None: return str(self.converted) @@ -646,7 +646,7 @@ def tostring(self, encoding) -> str: def maybe_expression(s) -> bool: - """ loose checking if s is a pytables-acceptable expression """ + """loose checking if s is a pytables-acceptable expression""" if not isinstance(s, str): return False ops = PyTablesExprVisitor.binary_ops + PyTablesExprVisitor.unary_ops + ("=",) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 28df7fc7c627d..433d45d94167d 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -111,7 +111,7 @@ def maybe_convert_platform( values: list | tuple | range | np.ndarray | ExtensionArray, ) -> ArrayLike: - """ try to do platform conversion, allow ndarray or list here """ + """try to do platform conversion, allow ndarray or list here""" arr: ArrayLike if isinstance(values, (list, tuple, range)): @@ -913,7 +913,7 @@ def invalidate_string_dtypes(dtype_set: set[DtypeObj]): def coerce_indexer_dtype(indexer, categories): - """ coerce the indexer input array to the smallest dtype possible """ + """coerce the indexer input array to the smallest dtype possible""" length = len(categories) if length < _int8_max: return ensure_int8(indexer) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 6b2a878f82786..34b9a3f1f14ad 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -142,7 +142,7 @@ def ensure_python_int(value: int | np.integer) -> int: def classes(*klasses) -> Callable: - """ evaluate if the tipo is a subclass of the klasses """ + """evaluate if the tipo is a subclass of the klasses""" return lambda tipo: issubclass(tipo, klasses) diff --git a/pandas/core/dtypes/dtypes.py b/pandas/core/dtypes/dtypes.py index aa6b67dd116df..51b0b746cadf9 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -104,7 +104,7 @@ def __getstate__(self) -> dict[str_type, Any]: @classmethod def reset_cache(cls) -> None: - """ clear the cache """ + """clear the cache""" cls._cache_dtypes = {} diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a9030d6da6cd5..1de19fceff258 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -252,7 +252,7 @@ def _init_mgr( dtype: Dtype | None = None, copy: bool_t = False, ) -> Manager: - """ passed a manager and a axes dict """ + """passed a manager and a axes dict""" for a, axe in axes.items(): if axe is not None: axe = ensure_index(axe) @@ -433,7 +433,7 @@ def set_flags( @final @classmethod def _validate_dtype(cls, dtype) -> DtypeObj | None: - """ validate the passed dtype """ + """validate the passed dtype""" if dtype is not None: dtype = pandas_dtype(dtype) @@ -4000,7 +4000,7 @@ def get(self, key, default=None): @final @property def _is_view(self) -> bool_t: - """Return boolean indicating if self is view of another array """ + """Return boolean indicating if self is view of another array""" return self._mgr.is_view @final @@ -4856,7 +4856,7 @@ def _reindex_with_indexers( copy: bool_t = False, allow_dups: bool_t = False, ) -> FrameOrSeries: - """allow_dups indicates an internal call here """ + """allow_dups indicates an internal call here""" # reindex doing multiple operations on different axes if indicated new_data = self._mgr for axis in sorted(reindexers.keys()): @@ -5575,7 +5575,7 @@ def _is_mixed_type(self) -> bool_t: @final def _check_inplace_setting(self, value) -> bool_t: - """ check whether we allow in-place setting with this type of value """ + """check whether we allow in-place setting with this type of value""" if self._is_mixed_type and not self._mgr.is_numeric_mixed_type: # allow an actual np.nan thru diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index 6903c8e99e489..b65f26c7174fc 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -824,7 +824,7 @@ def apply(self, f: F, data: FrameOrSeries, axis: int = 0): @cache_readonly def indices(self): - """ dict {group name -> group indices} """ + """dict {group name -> group indices}""" if len(self.groupings) == 1 and isinstance(self.result_index, CategoricalIndex): # This shows unused categories in indices GH#38642 return self.groupings[0].indices @@ -858,7 +858,7 @@ def size(self) -> Series: @cache_readonly def groups(self) -> dict[Hashable, np.ndarray]: - """ dict {group name -> group labels} """ + """dict {group name -> group labels}""" if len(self.groupings) == 1: return self.groupings[0].groups else: @@ -1132,7 +1132,7 @@ def __init__( @cache_readonly def groups(self): - """ dict {group name -> group labels} """ + """dict {group name -> group labels}""" # this is mainly for compat # GH 3881 result = { diff --git a/pandas/core/indexes/category.py b/pandas/core/indexes/category.py index ab44ae832c791..228f58d47b8ed 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -628,7 +628,7 @@ def _concat(self, to_concat: list[Index], name: Hashable) -> Index: return type(self)._simple_new(cat, name=name) def _delegate_method(self, name: str, *args, **kwargs): - """ method delegation to the ._values """ + """method delegation to the ._values""" method = getattr(self._values, name) if "inplace" in kwargs: raise ValueError("cannot use inplace with CategoricalIndex") diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 5e1e6c4928534..0876847aed84f 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1203,11 +1203,11 @@ def copy( return new_index def __array__(self, dtype=None) -> np.ndarray: - """ the array interface, return my values """ + """the array interface, return my values""" return self.values def view(self, cls=None): - """ this is defined as a copy with the same identity """ + """this is defined as a copy with the same identity""" result = self.copy() result._id = self._id return result @@ -1226,7 +1226,7 @@ def dtype(self) -> np.dtype: return np.dtype("O") def _is_memory_usage_qualified(self) -> bool: - """ return a boolean if we need a qualified .info display """ + """return a boolean if we need a qualified .info display""" def f(level): return "mixed" in level or "string" in level or "unicode" in level @@ -1242,7 +1242,7 @@ def memory_usage(self, deep: bool = False) -> int: @cache_readonly def nbytes(self) -> int: - """ return the number of bytes in the underlying data """ + """return the number of bytes in the underlying data""" return self._nbytes(False) def _nbytes(self, deep: bool = False) -> int: @@ -1583,7 +1583,7 @@ def is_monotonic_decreasing(self) -> bool: @cache_readonly def _inferred_type_levels(self) -> list[str]: - """ return a list of the inferred types, one for each level """ + """return a list of the inferred types, one for each level""" return [i.inferred_type for i in self.levels] @doc(Index.duplicated) diff --git a/pandas/core/indexes/range.py b/pandas/core/indexes/range.py index da6c061040282..746246172b967 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -173,7 +173,7 @@ def _simple_new(cls, values: range, name: Hashable = None) -> RangeIndex: @cache_readonly def _constructor(self) -> type[Int64Index]: - """ return the class to use for construction """ + """return the class to use for construction""" return Int64Index @cache_readonly @@ -197,7 +197,7 @@ def _int64index(self) -> Int64Index: return res def _get_data_as_items(self): - """ return a list of tuples of start, stop, step """ + """return a list of tuples of start, stop, step""" rng = self._range return [("start", rng.start), ("stop", rng.stop), ("step", rng.step)] @@ -350,7 +350,7 @@ def dtype(self) -> np.dtype: @property def is_unique(self) -> bool: - """ return if the index has unique values """ + """return if the index has unique values""" return True @cache_readonly diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index 31e32b053367b..76967cdc9b52e 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -433,7 +433,7 @@ def replace_list( inplace: bool = False, regex: bool = False, ) -> T: - """ do a list replace """ + """do a list replace""" inplace = validate_bool_kwarg(inplace, "inplace") return self.apply_with_block( @@ -462,7 +462,7 @@ def any_extension_types(self) -> bool: @property def is_view(self) -> bool: - """ return a boolean if we are a single block and are a view """ + """return a boolean if we are a single block and are a view""" # TODO what is this used for? return False diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 5f75ee81299af..2e7e6c7f7a100 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -169,7 +169,7 @@ def _consolidate_key(self): @property def is_view(self) -> bool: - """ return a boolean if I am possibly a view """ + """return a boolean if I am possibly a view""" values = self.values values = cast(np.ndarray, values) return values.base is not None @@ -262,7 +262,7 @@ def make_block(self, values, placement=None) -> Block: def make_block_same_class( self, values, placement: BlockPlacement | None = None ) -> Block: - """ Wrap given values in a block of same type as self. """ + """Wrap given values in a block of same type as self.""" if placement is None: placement = self._mgr_locs @@ -291,7 +291,7 @@ def __len__(self) -> int: return len(self.values) def _slice(self, slicer): - """ return a slice of my values """ + """return a slice of my values""" return self.values[slicer] @@ -530,7 +530,7 @@ def _maybe_downcast(self, blocks: list[Block], downcast=None) -> list[Block]: @final def downcast(self, dtypes=None) -> list[Block]: - """ try to downcast each item to the dict of dtypes if present """ + """try to downcast each item to the dict of dtypes if present""" # turn it off completely if dtypes is False: return [self] @@ -617,7 +617,7 @@ def convert( @final def _can_hold_element(self, element: Any) -> bool: - """ require the same dtype as ourselves """ + """require the same dtype as ourselves""" element = extract_array(element, extract_numpy=True) return can_hold_element(self.values, element) @@ -638,14 +638,14 @@ def should_store(self, value: ArrayLike) -> bool: @final def to_native_types(self, na_rep="nan", quoting=None, **kwargs): - """ convert to our native types format """ + """convert to our native types format""" result = to_native_types(self.values, na_rep=na_rep, quoting=quoting, **kwargs) return self.make_block(result) # block actions # @final def copy(self, deep: bool = True): - """ copy constructor """ + """copy constructor""" values = self.values if deep: values = values.copy() @@ -1158,12 +1158,12 @@ def take_nd( return self.make_block_same_class(new_values, new_mgr_locs) def diff(self, n: int, axis: int = 1) -> list[Block]: - """ return block for the diff of the values """ + """return block for the diff of the values""" new_values = algos.diff(self.values, n, axis=axis, stacklevel=7) return [self.make_block(values=new_values)] def shift(self, periods: int, axis: int = 0, fill_value: Any = None) -> list[Block]: - """ shift the block by periods, possibly upcast """ + """shift the block by periods, possibly upcast""" # convert integer to float if necessary. need to do a lot more than # that, handle boolean etc also @@ -1675,7 +1675,7 @@ class NDArrayBackedExtensionBlock(libinternals.NDArrayBackedBlock, EABackedBlock @property def is_view(self) -> bool: - """ return a boolean if I am possibly a view """ + """return a boolean if I am possibly a view""" # check the ndarray values of the DatetimeIndex values return self.values._ndarray.base is not None @@ -1771,7 +1771,7 @@ class DatetimeLikeBlock(NDArrayBackedExtensionBlock): class DatetimeTZBlock(DatetimeLikeBlock): - """ implement a datetime64 block with a tz attribute """ + """implement a datetime64 block with a tz attribute""" values: DatetimeArray @@ -1991,7 +1991,7 @@ def extract_pandas_array( def extend_blocks(result, blocks=None) -> list[Block]: - """ return a new extended blocks, given the result """ + """return a new extended blocks, given the result""" if blocks is None: blocks = [] if isinstance(result, list): @@ -2031,7 +2031,7 @@ def to_native_types( decimal=".", **kwargs, ) -> np.ndarray: - """ convert to our native types format """ + """convert to our native types format""" values = ensure_wrapped_if_datetimelike(values) if isinstance(values, (DatetimeArray, TimedeltaArray)): diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 323aa45874d96..48f0b7f7f964b 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -183,7 +183,7 @@ def blklocs(self): return self._blklocs def make_empty(self: T, axes=None) -> T: - """ return an empty BlockManager with the items axis of len 0 """ + """return an empty BlockManager with the items axis of len 0""" if axes is None: axes = [Index([])] + self.axes[1:] @@ -422,7 +422,7 @@ def replace_list( inplace: bool = False, regex: bool = False, ) -> T: - """ do a list replace """ + """do a list replace""" inplace = validate_bool_kwarg(inplace, "inplace") bm = self.apply( @@ -466,7 +466,7 @@ def any_extension_types(self) -> bool: @property def is_view(self) -> bool: - """ return a boolean if we are a single block and are a view """ + """return a boolean if we are a single block and are a view""" if len(self.blocks) == 1: return self.blocks[0].is_view @@ -516,7 +516,7 @@ def get_numeric_data(self: T, copy: bool = False) -> T: def _combine( self: T, blocks: list[Block], copy: bool = True, index: Index | None = None ) -> T: - """ return a new manager with the blocks """ + """return a new manager with the blocks""" if len(blocks) == 0: if self.ndim == 2: # retain our own Index dtype @@ -1502,7 +1502,7 @@ def _interleave( class SingleBlockManager(BaseBlockManager, SingleDataManager): - """ manage a single block with """ + """manage a single block with""" ndim = 1 _is_consolidated = True @@ -1596,12 +1596,12 @@ def _block(self) -> Block: @property def _blknos(self): - """ compat with BlockManager """ + """compat with BlockManager""" return None @property def _blklocs(self): - """ compat with BlockManager """ + """compat with BlockManager""" return None def getitem_mgr(self, indexer) -> SingleBlockManager: @@ -1759,7 +1759,7 @@ def construction_error( axes: list[Index], e: ValueError | None = None, ): - """ raise a helpful message about our construction """ + """raise a helpful message about our construction""" passed = tuple(map(int, [tot_items] + list(block_shape))) # Correcting the user facing error message during dataframe construction if len(passed) <= 2: @@ -1885,7 +1885,7 @@ def _simple_blockify(tuples, dtype, consolidate: bool) -> list[Block]: def _multi_blockify(tuples, dtype: DtypeObj | None = None, consolidate: bool = True): - """ return an array of blocks that potentially have different dtypes """ + """return an array of blocks that potentially have different dtypes""" if not consolidate: return _tuples_to_blocks_no_consolidate(tuples, dtype=dtype) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 673c482bced18..764f8621f5d26 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -191,7 +191,7 @@ def _has_infs(result) -> bool: def _get_fill_value( dtype: DtypeObj, fill_value: Scalar | None = None, fill_value_typ=None ): - """ return the correct fill value for the dtype of the values """ + """return the correct fill value for the dtype of the values""" if fill_value is not None: return fill_value if _na_ok_dtype(dtype): @@ -349,7 +349,7 @@ def _na_ok_dtype(dtype: DtypeObj) -> bool: def _wrap_results(result, dtype: np.dtype, fill_value=None): - """ wrap our results if needed """ + """wrap our results if needed""" if result is NaT: pass diff --git a/pandas/core/ops/__init__.py b/pandas/core/ops/__init__.py index 9cccf1cff60a1..297769149e5f0 100644 --- a/pandas/core/ops/__init__.py +++ b/pandas/core/ops/__init__.py @@ -149,7 +149,7 @@ def fill_binop(left, right, fill_value): def align_method_SERIES(left: Series, right, align_asobject: bool = False): - """ align lhs and rhs Series """ + """align lhs and rhs Series""" # ToDo: Different from align_method_FRAME, list, tuple and ndarray # are not coerced here # because Series has inconsistencies described in #13637 diff --git a/pandas/core/reshape/merge.py b/pandas/core/reshape/merge.py index c05130278f75b..143999a4677b3 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -931,7 +931,7 @@ def _maybe_add_join_keys( result.insert(i, name or f"key_{i}", key_col) def _get_join_indexers(self) -> tuple[np.ndarray, np.ndarray]: - """ return the join indexers """ + """return the join indexers""" # Both returned ndarrays are np.intp return get_join_indexers( self.left_join_keys, self.right_join_keys, sort=self.sort, how=self.how @@ -1692,7 +1692,7 @@ def _asof_by_function(direction: str): def _get_cython_type_upcast(dtype: DtypeObj) -> str: - """ Upcast a dtype to 'int64_t', 'double', or 'object' """ + """Upcast a dtype to 'int64_t', 'double', or 'object'""" if is_integer_dtype(dtype): return "int64_t" elif is_float_dtype(dtype): @@ -1883,10 +1883,10 @@ def _get_merge_keys(self): def _get_join_indexers(self) -> tuple[np.ndarray, np.ndarray]: # Both returned ndarrays are np.intp - """ return the join indexers """ + """return the join indexers""" def flip(xs) -> np.ndarray: - """ unlike np.transpose, this returns an array of tuples """ + """unlike np.transpose, this returns an array of tuples""" # error: Item "ndarray" of "Union[Any, Union[ExtensionArray, ndarray]]" has # no attribute "_values_for_argsort" xs = [ diff --git a/pandas/core/reshape/tile.py b/pandas/core/reshape/tile.py index 64daf2542e15a..7db30dc1ba9b9 100644 --- a/pandas/core/reshape/tile.py +++ b/pandas/core/reshape/tile.py @@ -552,7 +552,7 @@ def _convert_bin_to_datelike_type(bins, dtype): def _format_labels( bins, precision: int, right: bool = True, include_lowest: bool = False, dtype=None ): - """ based on the dtype, return our labels """ + """based on the dtype, return our labels""" closed = "right" if right else "left" formatter: Callable[[Any], Timestamp] | Callable[[Any], Timedelta] diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 485610af747f6..32a5cda4f4083 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1541,7 +1541,7 @@ def __init__( self.date_format = date_format def _format_strings(self) -> list[str]: - """ we by definition have DO NOT have a TZ """ + """we by definition have DO NOT have a TZ""" values = self.values if not isinstance(values, DatetimeIndex): @@ -1729,7 +1729,7 @@ def get_format_datetime64( def get_format_datetime64_from_values( values: np.ndarray | DatetimeArray | DatetimeIndex, date_format: str | None ) -> str | None: - """ given values and a date_format, return a string format """ + """given values and a date_format, return a string format""" if isinstance(values, np.ndarray) and values.ndim > 1: # We don't actually care about the order of values, and DatetimeIndex # only accepts 1D values @@ -1743,7 +1743,7 @@ def get_format_datetime64_from_values( class Datetime64TZFormatter(Datetime64Formatter): def _format_strings(self) -> list[str]: - """ we by definition have a TZ """ + """we by definition have a TZ""" values = self.values.astype(object) ido = is_dates_only(values) formatter = self.formatter or get_format_datetime64( diff --git a/pandas/io/parquet.py b/pandas/io/parquet.py index 1d96f07e2f9ca..b7523fada07d0 100644 --- a/pandas/io/parquet.py +++ b/pandas/io/parquet.py @@ -35,7 +35,7 @@ def get_engine(engine: str) -> BaseImpl: - """ return our implementation """ + """return our implementation""" if engine == "auto": engine = get_option("io.parquet.engine") diff --git a/pandas/io/parsers/readers.py b/pandas/io/parsers/readers.py index 8a48e8970f1f7..06bdbe3054a15 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -1191,7 +1191,7 @@ def _floatify_na_values(na_values): def _stringify_na_values(na_values): - """ return a stringified and numeric for these values """ + """return a stringified and numeric for these values""" result: list[int | str | float] = [] for x in na_values: result.append(str(x)) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 27c30aa4c10ad..0eae6ea5d6b7b 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -112,7 +112,7 @@ def _ensure_decoded(s): - """ if we have bytes, decode them to unicode """ + """if we have bytes, decode them to unicode""" if isinstance(s, np.bytes_): s = s.decode("UTF-8") return s @@ -274,7 +274,7 @@ def to_hdf( errors: str = "strict", encoding: str = "UTF-8", ): - """ store this object, close it if we opened it """ + """store this object, close it if we opened it""" if append: f = lambda store: store.append( key, @@ -592,7 +592,7 @@ def __fspath__(self): @property def root(self): - """ return the root node """ + """return the root node""" self._check_if_open() assert self._handle is not None # for mypy return self._handle.root @@ -611,7 +611,7 @@ def __delitem__(self, key: str): return self.remove(key) def __getattr__(self, name: str): - """ allow attribute access to get stores """ + """allow attribute access to get stores""" try: return self.get(name) except (KeyError, ClosedFileError): @@ -1489,7 +1489,7 @@ def walk(self, where="/"): yield (g._v_pathname.rstrip("/"), groups, leaves) def get_node(self, key: str) -> Node | None: - """ return the node with the key or None if it does not exist """ + """return the node with the key or None if it does not exist""" self._check_if_open() if not key.startswith("/"): key = "/" + key @@ -1505,7 +1505,7 @@ def get_node(self, key: str) -> Node | None: return node def get_storer(self, key: str) -> GenericFixed | Table: - """ return the storer object for a key, raise if not in the file """ + """return the storer object for a key, raise if not in the file""" group = self.get_node(key) if group is None: raise KeyError(f"No object named {key} in the file") @@ -1622,7 +1622,7 @@ def _check_if_open(self): raise ClosedFileError(f"{self._path} file is not open!") def _validate_format(self, format: str) -> str: - """ validate / deprecate formats """ + """validate / deprecate formats""" # validate try: format = _FORMAT_MAP[format.lower()] @@ -1639,7 +1639,7 @@ def _create_storer( encoding: str = "UTF-8", errors: str = "strict", ) -> GenericFixed | Table: - """ return a suitable class to operate """ + """return a suitable class to operate""" cls: type[GenericFixed] | type[Table] if value is not None and not isinstance(value, (Series, DataFrame)): @@ -2017,7 +2017,7 @@ def kind_attr(self) -> str: return f"{self.name}_kind" def set_pos(self, pos: int): - """ set the position of this column in the Table """ + """set the position of this column in the Table""" self.pos = pos if pos is not None and self.typ is not None: self.typ._v_pos = pos @@ -2034,7 +2034,7 @@ def __repr__(self) -> str: ) def __eq__(self, other: Any) -> bool: - """ compare 2 col items """ + """compare 2 col items""" return all( getattr(self, a, None) == getattr(other, a, None) for a in ["name", "cname", "axis", "pos"] @@ -2045,7 +2045,7 @@ def __ne__(self, other) -> bool: @property def is_indexed(self) -> bool: - """ return whether I am an indexed column """ + """return whether I am an indexed column""" if not hasattr(self.table, "cols"): # e.g. if infer hasn't been called yet, self.table will be None. return False @@ -2090,7 +2090,7 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str): return new_pd_index, new_pd_index def take_data(self): - """ return the values""" + """return the values""" return self.values @property @@ -2103,12 +2103,12 @@ def description(self): @property def col(self): - """ return my current col description """ + """return my current col description""" return getattr(self.description, self.cname, None) @property def cvalues(self): - """ return my cython values """ + """return my cython values""" return self.values def __iter__(self): @@ -2139,7 +2139,7 @@ def validate_and_set(self, handler: AppendableTable, append: bool): self.set_attr() def validate_col(self, itemsize=None): - """ validate this column: return the compared against itemsize """ + """validate this column: return the compared against itemsize""" # validate this column for string truncation (or reset to the max size) if _ensure_decoded(self.kind) == "string": c = self.col @@ -2198,17 +2198,17 @@ def update_info(self, info): idx[key] = value def set_info(self, info): - """ set my state from the passed info """ + """set my state from the passed info""" idx = info.get(self.name) if idx is not None: self.__dict__.update(idx) def set_attr(self): - """ set the kind for this column """ + """set the kind for this column""" setattr(self.attrs, self.kind_attr, self.kind) def validate_metadata(self, handler: AppendableTable): - """ validate that kind=category does not change the categories """ + """validate that kind=category does not change the categories""" if self.meta == "category": new_metadata = self.metadata cur_metadata = handler.read_metadata(self.cname) @@ -2223,13 +2223,13 @@ def validate_metadata(self, handler: AppendableTable): ) def write_metadata(self, handler: AppendableTable): - """ set the meta data """ + """set the meta data""" if self.metadata is not None: handler.write_metadata(self.cname, self.metadata) class GenericIndexCol(IndexCol): - """ an index which is not represented in the data of the table """ + """an index which is not represented in the data of the table""" @property def is_indexed(self) -> bool: @@ -2328,7 +2328,7 @@ def __repr__(self) -> str: ) def __eq__(self, other: Any) -> bool: - """ compare 2 col items """ + """compare 2 col items""" return all( getattr(self, a, None) == getattr(other, a, None) for a in ["name", "cname", "dtype", "pos"] @@ -2345,7 +2345,7 @@ def set_data(self, data: ArrayLike): self.kind = _dtype_to_kind(dtype_name) def take_data(self): - """ return the data """ + """return the data""" return self.data @classmethod @@ -2386,7 +2386,7 @@ def get_atom_string(cls, shape, itemsize): @classmethod def get_atom_coltype(cls, kind: str) -> type[Col]: - """ return the PyTables column class for this column """ + """return the PyTables column class for this column""" if kind.startswith("uint"): k4 = kind[4:] col_name = f"UInt{k4}Col" @@ -2417,7 +2417,7 @@ def shape(self): @property def cvalues(self): - """ return my cython values """ + """return my cython values""" return self.data def validate_attr(self, append): @@ -2535,7 +2535,7 @@ def convert(self, values: np.ndarray, nan_rep, encoding: str, errors: str): return self.values, converted def set_attr(self): - """ set the data for this column """ + """set the data for this column""" setattr(self.attrs, self.kind_attr, self.values) setattr(self.attrs, self.meta_attr, self.meta) assert self.dtype is not None @@ -2543,7 +2543,7 @@ def set_attr(self): class DataIndexableCol(DataCol): - """ represent a data column that can be indexed """ + """represent a data column that can be indexed""" is_data_indexable = True @@ -2570,7 +2570,7 @@ def get_atom_timedelta64(cls, shape): class GenericDataIndexableCol(DataIndexableCol): - """ represent a generic pytables data column """ + """represent a generic pytables data column""" pass @@ -2619,7 +2619,7 @@ def is_old_version(self) -> bool: @property def version(self) -> tuple[int, int, int]: - """ compute and set our version """ + """compute and set our version""" version = _ensure_decoded(getattr(self.group._v_attrs, "pandas_version", None)) try: version = tuple(int(x) for x in version.split(".")) @@ -2634,7 +2634,7 @@ def pandas_type(self): return _ensure_decoded(getattr(self.group._v_attrs, "pandas_type", None)) def __repr__(self) -> str: - """ return a pretty representation of myself """ + """return a pretty representation of myself""" self.infer_axes() s = self.shape if s is not None: @@ -2645,7 +2645,7 @@ def __repr__(self) -> str: return self.pandas_type def set_object_info(self): - """ set my pandas type & version """ + """set my pandas type & version""" self.attrs.pandas_type = str(self.pandas_kind) self.attrs.pandas_version = str(_version) @@ -2682,16 +2682,16 @@ def attrs(self): return self.group._v_attrs def set_attrs(self): - """ set our object attributes """ + """set our object attributes""" pass def get_attrs(self): - """ get our object attributes """ + """get our object attributes""" pass @property def storable(self): - """ return my storable """ + """return my storable""" return self.group @property @@ -2703,13 +2703,13 @@ def nrows(self): return getattr(self.storable, "nrows", None) def validate(self, other): - """ validate against an existing storable """ + """validate against an existing storable""" if other is None: return return True def validate_version(self, where=None): - """ are we trying to operate on an old version? """ + """are we trying to operate on an old version?""" return True def infer_axes(self): @@ -2752,7 +2752,7 @@ def delete(self, where=None, start: int | None = None, stop: int | None = None): class GenericFixed(Fixed): - """ a generified fixed version """ + """a generified fixed version""" _index_type_map = {DatetimeIndex: "datetime", PeriodIndex: "period"} _reverse_index_map = {v: k for k, v in _index_type_map.items()} @@ -2834,12 +2834,12 @@ def is_exists(self) -> bool: return True def set_attrs(self): - """ set our object attributes """ + """set our object attributes""" self.attrs.encoding = self.encoding self.attrs.errors = self.errors def get_attrs(self): - """ retrieve our attributes """ + """retrieve our attributes""" self.encoding = _ensure_encoding(getattr(self.attrs, "encoding", None)) self.errors = _ensure_decoded(getattr(self.attrs, "errors", "strict")) for n in self.attributes: @@ -2849,7 +2849,7 @@ def write(self, obj, **kwargs): self.set_attrs() def read_array(self, key: str, start: int | None = None, stop: int | None = None): - """ read an array for the specified node (off of group """ + """read an array for the specified node (off of group""" import tables node = getattr(self.group, key) @@ -3006,7 +3006,7 @@ def read_index_node( return index def write_array_empty(self, key: str, value: ArrayLike): - """ write a 0-len array """ + """write a 0-len array""" # ugly hack for length 0 axes arr = np.empty((1,) * value.ndim) self._handle.create_array(self.group, key, arr) @@ -3294,7 +3294,7 @@ def table_type_short(self) -> str: return self.table_type.split("_")[0] def __repr__(self) -> str: - """ return a pretty representation of myself """ + """return a pretty representation of myself""" self.infer_axes() jdc = ",".join(self.data_columns) if len(self.data_columns) else "" dc = f",dc->[{jdc}]" @@ -3312,14 +3312,14 @@ def __repr__(self) -> str: ) def __getitem__(self, c: str): - """ return the axis for c """ + """return the axis for c""" for a in self.axes: if c == a.name: return a return None def validate(self, other): - """ validate against an existing table """ + """validate against an existing table""" if other is None: return @@ -3375,12 +3375,12 @@ def validate_multiindex( @property def nrows_expected(self) -> int: - """ based on our axes, compute the expected nrows """ + """based on our axes, compute the expected nrows""" return np.prod([i.cvalues.shape[0] for i in self.index_axes]) @property def is_exists(self) -> bool: - """ has this table been created """ + """has this table been created""" return "table" in self.group @property @@ -3389,7 +3389,7 @@ def storable(self): @property def table(self): - """ return the table group (this is my storable) """ + """return the table group (this is my storable)""" return self.storable @property @@ -3406,7 +3406,7 @@ def axes(self): @property def ncols(self) -> int: - """ the number of total columns in the values axes """ + """the number of total columns in the values axes""" return sum(len(a.values) for a in self.values_axes) @property @@ -3424,7 +3424,7 @@ def data_orientation(self): ) def queryables(self) -> dict[str, Any]: - """ return a dict of the kinds allowable columns for this object """ + """return a dict of the kinds allowable columns for this object""" # mypy doesn't recognize DataFrame._AXIS_NAMES, so we re-write it here axis_names = {0: "index", 1: "columns"} @@ -3440,16 +3440,16 @@ def queryables(self) -> dict[str, Any]: return dict(d1 + d2 + d3) # type: ignore[operator] def index_cols(self): - """ return a list of my index cols """ + """return a list of my index cols""" # Note: each `i.cname` below is assured to be a str. return [(i.axis, i.cname) for i in self.index_axes] def values_cols(self) -> list[str]: - """ return a list of my values cols """ + """return a list of my values cols""" return [i.cname for i in self.values_axes] def _get_metadata_path(self, key: str) -> str: - """ return the metadata pathname for this key """ + """return the metadata pathname for this key""" group = self.group._v_pathname return f"{group}/meta/{key}/meta" @@ -3477,13 +3477,13 @@ def write_metadata(self, key: str, values: np.ndarray): ) def read_metadata(self, key: str): - """ return the meta data array for this key """ + """return the meta data array for this key""" if getattr(getattr(self.group, "meta", None), key, None) is not None: return self.parent.select(self._get_metadata_path(key)) return None def set_attrs(self): - """ set our table type & indexables """ + """set our table type & indexables""" self.attrs.table_type = str(self.table_type) self.attrs.index_cols = self.index_cols() self.attrs.values_cols = self.values_cols() @@ -3496,7 +3496,7 @@ def set_attrs(self): self.attrs.info = self.info def get_attrs(self): - """ retrieve our attributes """ + """retrieve our attributes""" self.non_index_axes = getattr(self.attrs, "non_index_axes", None) or [] self.data_columns = getattr(self.attrs, "data_columns", None) or [] self.info = getattr(self.attrs, "info", None) or {} @@ -3508,7 +3508,7 @@ def get_attrs(self): self.values_axes = [a for a in self.indexables if not a.is_an_indexable] def validate_version(self, where=None): - """ are we trying to operate on an old version? """ + """are we trying to operate on an old version?""" if where is not None: if self.version[0] <= 0 and self.version[1] <= 10 and self.version[2] < 1: ws = incompatibility_doc % ".".join(str(x) for x in self.version) @@ -3538,7 +3538,7 @@ def validate_min_itemsize(self, min_itemsize): @cache_readonly def indexables(self): - """ create/cache the indexables if they don't exist """ + """create/cache the indexables if they don't exist""" _indexables = [] desc = self.description @@ -3730,7 +3730,7 @@ def _read_axes( @classmethod def get_object(cls, obj, transposed: bool): - """ return the data for this obj """ + """return the data for this obj""" return obj def validate_data_columns(self, data_columns, min_itemsize, non_index_axes): @@ -4065,7 +4065,7 @@ def get_blk_items(mgr): return blocks, blk_items def process_axes(self, obj, selection: Selection, columns=None): - """ process axes filters """ + """process axes filters""" # make a copy to avoid side effects if columns is not None: columns = list(columns) @@ -4129,7 +4129,7 @@ def create_description( fletcher32: bool, expectedrows: int | None, ) -> dict[str, Any]: - """ create the description of the table from the axes & values """ + """create the description of the table from the axes & values""" # provided expected rows if its passed if expectedrows is None: expectedrows = max(self.nrows_expected, 10000) @@ -4254,7 +4254,7 @@ def write(self, **kwargs): class AppendableTable(Table): - """ support the new appendable table formats """ + """support the new appendable table formats""" table_type = "appendable" @@ -4483,7 +4483,7 @@ def delete(self, where=None, start: int | None = None, stop: int | None = None): class AppendableFrameTable(AppendableTable): - """ support the new appendable table formats """ + """support the new appendable table formats""" pandas_kind = "frame_table" table_type = "appendable_frame" @@ -4496,7 +4496,7 @@ def is_transposed(self) -> bool: @classmethod def get_object(cls, obj, transposed: bool): - """ these are written transposed """ + """these are written transposed""" if transposed: obj = obj.T return obj @@ -4583,7 +4583,7 @@ def read( class AppendableSeriesTable(AppendableFrameTable): - """ support the new appendable table formats """ + """support the new appendable table formats""" pandas_kind = "series_table" table_type = "appendable_series" @@ -4599,7 +4599,7 @@ def get_object(cls, obj, transposed: bool): return obj def write(self, obj, data_columns=None, **kwargs): - """ we are going to write this as a frame table """ + """we are going to write this as a frame table""" if not isinstance(obj, DataFrame): name = obj.name or "values" obj = obj.to_frame(name) @@ -4632,13 +4632,13 @@ def read( class AppendableMultiSeriesTable(AppendableSeriesTable): - """ support the new appendable table formats """ + """support the new appendable table formats""" pandas_kind = "series_table" table_type = "appendable_multiseries" def write(self, obj, **kwargs): - """ we are going to write this as a frame table """ + """we are going to write this as a frame table""" name = obj.name or "values" newobj, self.levels = self.validate_multiindex(obj) assert isinstance(self.levels, list) # for mypy @@ -4649,7 +4649,7 @@ def write(self, obj, **kwargs): class GenericTable(AppendableFrameTable): - """ a table that read/writes the generic pytables table format """ + """a table that read/writes the generic pytables table format""" pandas_kind = "frame_table" table_type = "generic_table" @@ -4666,7 +4666,7 @@ def storable(self): return getattr(self.group, "table", None) or self.group def get_attrs(self): - """ retrieve our attributes """ + """retrieve our attributes""" self.non_index_axes = [] self.nan_rep = None self.levels = [] @@ -4677,7 +4677,7 @@ def get_attrs(self): @cache_readonly def indexables(self): - """ create the indexables from the table description """ + """create the indexables from the table description""" d = self.description # TODO: can we get a typ for this? AFAICT it is the only place @@ -4715,7 +4715,7 @@ def write(self, **kwargs): class AppendableMultiFrameTable(AppendableFrameTable): - """ a frame with a multi-index """ + """a frame with a multi-index""" table_type = "appendable_multiframe" obj_type = DataFrame @@ -4782,7 +4782,7 @@ def _reindex_axis(obj: DataFrame, axis: int, labels: Index, other=None) -> DataF def _get_tz(tz: tzinfo) -> str | tzinfo: - """ for a tz-aware type, return an encoded zone """ + """for a tz-aware type, return an encoded zone""" zone = timezones.get_timezone(tz) return zone @@ -5230,7 +5230,7 @@ def __init__( self.condition, self.filter = self.terms.evaluate() def generate(self, where): - """ where can be a : dict,list,tuple,string """ + """where can be a : dict,list,tuple,string""" if where is None: return None diff --git a/pandas/io/sas/sas_xport.py b/pandas/io/sas/sas_xport.py index f7e1c56cbb196..6ced3febd78f4 100644 --- a/pandas/io/sas/sas_xport.py +++ b/pandas/io/sas/sas_xport.py @@ -138,7 +138,7 @@ def _parse_date(datestr: str) -> datetime: - """ Given a date in xport format, return Python date. """ + """Given a date in xport format, return Python date.""" try: # e.g. "16FEB11:10:07:55" return datetime.strptime(datestr, "%d%b%y:%H:%M:%S") diff --git a/pandas/io/sql.py b/pandas/io/sql.py index 7ff7060167fc8..b9d5b18b85e02 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1351,7 +1351,7 @@ def insert_records( def get_engine(engine: str) -> BaseEngine: - """ return our implementation """ + """return our implementation""" if engine == "auto": engine = get_option("io.sql.engine") diff --git a/pandas/io/stata.py b/pandas/io/stata.py index 1fef33558dd9a..ffaebb3c10ae2 100644 --- a/pandas/io/stata.py +++ b/pandas/io/stata.py @@ -1095,15 +1095,15 @@ def __init__( self._setup_dtype() def __enter__(self) -> StataReader: - """ enter context manager """ + """enter context manager""" return self def __exit__(self, exc_type, exc_value, traceback) -> None: - """ exit context manager """ + """exit context manager""" self.close() def close(self) -> None: - """ close the handle if its open """ + """close the handle if its open""" self.path_or_buf.close() def _set_encoding(self) -> None: diff --git a/pandas/tests/arithmetic/test_period.py b/pandas/tests/arithmetic/test_period.py index bb78e29924ba2..5f93442cae4f6 100644 --- a/pandas/tests/arithmetic/test_period.py +++ b/pandas/tests/arithmetic/test_period.py @@ -444,7 +444,7 @@ def test_cmp_series_period_series_mixed_freq(self): class TestPeriodIndexSeriesComparisonConsistency: - """ Test PeriodIndex and Period Series Ops consistency """ + """Test PeriodIndex and Period Series Ops consistency""" # TODO: needs parametrization+de-duplication @@ -1306,7 +1306,7 @@ def test_ops_series_period(self): class TestPeriodIndexSeriesMethods: - """ Test PeriodIndex and Period Series Ops consistency """ + """Test PeriodIndex and Period Series Ops consistency""" def _check(self, values, func, expected): idx = PeriodIndex(values) diff --git a/pandas/tests/base/test_constructors.py b/pandas/tests/base/test_constructors.py index ceb882ff9c963..16ce709a5b021 100644 --- a/pandas/tests/base/test_constructors.py +++ b/pandas/tests/base/test_constructors.py @@ -47,7 +47,7 @@ def _get_foo(self): foo = property(_get_foo, _set_foo, doc="foo property") def bar(self, *args, **kwargs): - """ a test bar method """ + """a test bar method""" pass class Delegate(PandasDelegate, PandasObject): diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index bfe431f93b725..a2244c4aab923 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -25,12 +25,12 @@ # EA & Actual Dtypes def to_ea_dtypes(dtypes): - """ convert list of string dtypes to EA dtype """ + """convert list of string dtypes to EA dtype""" return [getattr(pd, dt + "Dtype") for dt in dtypes] def to_numpy_dtypes(dtypes): - """ convert list of string dtypes to numpy dtype """ + """convert list of string dtypes to numpy dtype""" return [getattr(np, dt) for dt in dtypes if isinstance(dt, str)] diff --git a/pandas/tests/extension/base/reduce.py b/pandas/tests/extension/base/reduce.py index 0f7bd59411eb5..c6a35d8fa5b38 100644 --- a/pandas/tests/extension/base/reduce.py +++ b/pandas/tests/extension/base/reduce.py @@ -20,7 +20,7 @@ def check_reduce(self, s, op_name, skipna): class BaseNoReduceTests(BaseReduceTests): - """ we don't define any reductions """ + """we don't define any reductions""" @pytest.mark.parametrize("skipna", [True, False]) def test_reduce_series_numeric(self, data, all_numeric_reductions, skipna): diff --git a/pandas/tests/frame/methods/test_clip.py b/pandas/tests/frame/methods/test_clip.py index 09b33831ed5ec..7258f5eceb54a 100644 --- a/pandas/tests/frame/methods/test_clip.py +++ b/pandas/tests/frame/methods/test_clip.py @@ -139,7 +139,7 @@ def test_clip_against_unordered_columns(self): tm.assert_frame_equal(result_lower_upper, expected_lower_upper) def test_clip_with_na_args(self, float_frame): - """Should process np.nan argument as None """ + """Should process np.nan argument as None""" # GH#17276 tm.assert_frame_equal(float_frame.clip(np.nan), float_frame) tm.assert_frame_equal(float_frame.clip(upper=np.nan, lower=np.nan), float_frame) diff --git a/pandas/tests/generic/test_generic.py b/pandas/tests/generic/test_generic.py index 254a0b8dfd34e..3a307ebd702ca 100644 --- a/pandas/tests/generic/test_generic.py +++ b/pandas/tests/generic/test_generic.py @@ -24,7 +24,7 @@ def _ndim(self): return self._typ._AXIS_LEN def _axes(self): - """ return the axes for my object typ """ + """return the axes for my object typ""" return self._typ._AXIS_ORDERS def _construct(self, shape, value=None, dtype=None, **kwargs): diff --git a/pandas/tests/generic/test_label_or_level_utils.py b/pandas/tests/generic/test_label_or_level_utils.py index d3566f16ab49f..87bb6a58600f4 100644 --- a/pandas/tests/generic/test_label_or_level_utils.py +++ b/pandas/tests/generic/test_label_or_level_utils.py @@ -9,13 +9,13 @@ # ======== @pytest.fixture def df(): - """DataFrame with columns 'L1', 'L2', and 'L3' """ + """DataFrame with columns 'L1', 'L2', and 'L3'""" return pd.DataFrame({"L1": [1, 2, 3], "L2": [11, 12, 13], "L3": ["A", "B", "C"]}) @pytest.fixture(params=[[], ["L1"], ["L1", "L2"], ["L1", "L2", "L3"]]) def df_levels(request, df): - """DataFrame with columns or index levels 'L1', 'L2', and 'L3' """ + """DataFrame with columns or index levels 'L1', 'L2', and 'L3'""" levels = request.param if levels: @@ -26,7 +26,7 @@ def df_levels(request, df): @pytest.fixture def df_ambig(df): - """DataFrame with levels 'L1' and 'L2' and labels 'L1' and 'L3' """ + """DataFrame with levels 'L1' and 'L2' and labels 'L1' and 'L3'""" df = df.set_index(["L1", "L2"]) df["L1"] = df["L3"] @@ -36,7 +36,7 @@ def df_ambig(df): @pytest.fixture def df_duplabels(df): - """DataFrame with level 'L1' and labels 'L2', 'L3', and 'L2' """ + """DataFrame with level 'L1' and labels 'L2', 'L3', and 'L2'""" df = df.set_index(["L1"]) df = pd.concat([df, df["L2"]], axis=1) diff --git a/pandas/tests/indexing/common.py b/pandas/tests/indexing/common.py index f7c2266e39fcc..8cde03af1ff92 100644 --- a/pandas/tests/indexing/common.py +++ b/pandas/tests/indexing/common.py @@ -26,7 +26,7 @@ def _axify(obj, key, axis): class Base: - """ indexing comprehensive base class """ + """indexing comprehensive base class""" _kinds = {"series", "frame"} _typs = { @@ -120,7 +120,7 @@ def generate_indices(self, f, values=False): return itertools.product(*axes) def get_value(self, name, f, i, values=False): - """ return the value for the location i """ + """return the value for the location i""" # check against values if values: return f.values[i] @@ -153,7 +153,7 @@ def check_values(self, f, func, values=False): def check_result(self, method, key, typs=None, axes=None, fails=None): def _eq(axis, obj, key): - """ compare equal for these 2 keys """ + """compare equal for these 2 keys""" axified = _axify(obj, key, axis) try: getattr(obj, method).__getitem__(axified) diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 145f9741d03d1..7911cd7f12e0c 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -77,7 +77,7 @@ class TestSetitemCoercion(CoercionBase): def _assert_setitem_series_conversion( self, original_series, loc_value, expected_series, expected_dtype ): - """ test series value's coercion triggered by assignment """ + """test series value's coercion triggered by assignment""" temp = original_series.copy() temp[1] = loc_value tm.assert_series_equal(temp, expected_series) @@ -271,7 +271,7 @@ def test_setitem_series_no_coercion_from_values_list(self): def _assert_setitem_index_conversion( self, original_series, loc_key, expected_index, expected_dtype ): - """ test index's coercion triggered by assign key """ + """test index's coercion triggered by assign key""" temp = original_series.copy() temp[loc_key] = 5 exp = pd.Series([1, 2, 3, 4, 5], index=expected_index) @@ -365,7 +365,7 @@ class TestInsertIndexCoercion(CoercionBase): method = "insert" def _assert_insert_conversion(self, original, value, expected, expected_dtype): - """ test coercion triggered by insert """ + """test coercion triggered by insert""" target = original.copy() res = target.insert(1, value) tm.assert_index_equal(res, expected) @@ -553,7 +553,7 @@ class TestWhereCoercion(CoercionBase): def _assert_where_conversion( self, original, cond, values, expected, expected_dtype ): - """ test coercion triggered by where """ + """test coercion triggered by where""" target = original.copy() res = target.where(cond, values) tm.assert_equal(res, expected) @@ -867,7 +867,7 @@ def test_has_comprehensive_tests(self): raise NotImplementedError def _assert_fillna_conversion(self, original, value, expected, expected_dtype): - """ test coercion triggered by fillna """ + """test coercion triggered by fillna""" target = original.copy() res = target.fillna(value) tm.assert_equal(res, expected) diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index 425c68725c595..c945bd6b95ee1 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -33,7 +33,7 @@ class TestFancy: - """ pure get/set item & fancy indexing """ + """pure get/set item & fancy indexing""" def test_setitem_ndarray_1d(self): # GH5508 diff --git a/pandas/tests/internals/test_internals.py b/pandas/tests/internals/test_internals.py index 61bbd4e12e1ba..0f4a30cfa9cf9 100644 --- a/pandas/tests/internals/test_internals.py +++ b/pandas/tests/internals/test_internals.py @@ -561,7 +561,7 @@ def test_astype(self, t): def test_convert(self): def _compare(old_mgr, new_mgr): - """ compare the blocks, numeric compare ==, object don't """ + """compare the blocks, numeric compare ==, object don't""" old_blocks = set(old_mgr.blocks) new_blocks = set(new_mgr.blocks) assert len(old_blocks) == len(new_blocks) diff --git a/pandas/tests/io/generate_legacy_storage_files.py b/pandas/tests/io/generate_legacy_storage_files.py index 601b50fb469cb..dede9127821fd 100644 --- a/pandas/tests/io/generate_legacy_storage_files.py +++ b/pandas/tests/io/generate_legacy_storage_files.py @@ -125,7 +125,7 @@ def _create_sp_frame(): def create_data(): - """ create the pickle data """ + """create the pickle data""" data = { "A": [0.0, 1.0, 2.0, 3.0, np.nan], "B": [0, 1, 0, 1, 0], diff --git a/pandas/tests/io/pytables/common.py b/pandas/tests/io/pytables/common.py index 6a9d5745ab457..67c3a2902dbcb 100644 --- a/pandas/tests/io/pytables/common.py +++ b/pandas/tests/io/pytables/common.py @@ -30,7 +30,7 @@ def safe_close(store): def create_tempfile(path): - """ create an unopened named temporary file """ + """create an unopened named temporary file""" return os.path.join(tempfile.gettempdir(), path) diff --git a/pandas/tests/io/pytables/conftest.py b/pandas/tests/io/pytables/conftest.py index 38ffcb3b0e8ec..988f78c5ae843 100644 --- a/pandas/tests/io/pytables/conftest.py +++ b/pandas/tests/io/pytables/conftest.py @@ -11,7 +11,7 @@ def setup_path(): @pytest.fixture(scope="module", autouse=True) def setup_mode(): - """ Reset testing mode fixture""" + """Reset testing mode fixture""" tm.reset_testing_mode() yield tm.set_testing_mode() diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 329ace02f4207..ccd0bc3d16896 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -1753,7 +1753,7 @@ def _check(axes): @td.skip_if_no_scipy def test_memory_leak(self): - """ Check that every plot type gets properly collected. """ + """Check that every plot type gets properly collected.""" import gc import weakref diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 7f0d1802580b9..adda95f4c5aa0 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -272,7 +272,7 @@ def test_parallel_coordinates(self, iris): # not sure if this is indicative of a problem @pytest.mark.filterwarnings("ignore:Attempting to set:UserWarning") def test_parallel_coordinates_with_sorted_labels(self): - """ For #15908 """ + """For #15908""" from pandas.plotting import parallel_coordinates df = DataFrame( diff --git a/pandas/tests/resample/test_base.py b/pandas/tests/resample/test_base.py index bf3e6d822ab19..450bd8b05ea43 100644 --- a/pandas/tests/resample/test_base.py +++ b/pandas/tests/resample/test_base.py @@ -36,7 +36,7 @@ @pytest.fixture def create_index(_index_factory): def _create_index(*args, **kwargs): - """ return the _index_factory created using the args, kwargs """ + """return the _index_factory created using the args, kwargs""" return _index_factory(*args, **kwargs) return _create_index diff --git a/pandas/tests/resample/test_deprecated.py b/pandas/tests/resample/test_deprecated.py index 1f99c2888aad5..359c3cea62f9c 100644 --- a/pandas/tests/resample/test_deprecated.py +++ b/pandas/tests/resample/test_deprecated.py @@ -42,7 +42,7 @@ def _index_factory(): @pytest.fixture def create_index(_index_factory): def _create_index(*args, **kwargs): - """ return the _index_factory created using the args, kwargs """ + """return the _index_factory created using the args, kwargs""" return _index_factory(*args, **kwargs) return _create_index diff --git a/pandas/tests/reshape/merge/test_merge_asof.py b/pandas/tests/reshape/merge/test_merge_asof.py index 671f0ad2d26c7..6746158179964 100644 --- a/pandas/tests/reshape/merge/test_merge_asof.py +++ b/pandas/tests/reshape/merge/test_merge_asof.py @@ -40,7 +40,7 @@ def setup_method(self, datapath): ) def test_examples1(self): - """ doc-string examples """ + """doc-string examples""" left = pd.DataFrame({"a": [1, 5, 10], "left_val": ["a", "b", "c"]}) right = pd.DataFrame({"a": [1, 2, 3, 6, 7], "right_val": [1, 2, 3, 6, 7]}) @@ -52,7 +52,7 @@ def test_examples1(self): tm.assert_frame_equal(result, expected) def test_examples2(self): - """ doc-string examples """ + """doc-string examples""" trades = pd.DataFrame( { "time": to_datetime( @@ -136,7 +136,7 @@ def test_examples2(self): tm.assert_frame_equal(result, expected) def test_examples3(self): - """ doc-string examples """ + """doc-string examples""" # GH14887 left = pd.DataFrame({"a": [1, 5, 10], "left_val": ["a", "b", "c"]}) @@ -150,7 +150,7 @@ def test_examples3(self): tm.assert_frame_equal(result, expected) def test_examples4(self): - """ doc-string examples """ + """doc-string examples""" # GH14887 left = pd.DataFrame({"a": [1, 5, 10], "left_val": ["a", "b", "c"]}) diff --git a/pandas/tests/series/methods/test_clip.py b/pandas/tests/series/methods/test_clip.py index 7dbc194669a62..e4803a9cd3038 100644 --- a/pandas/tests/series/methods/test_clip.py +++ b/pandas/tests/series/methods/test_clip.py @@ -61,7 +61,7 @@ def test_series_clipping_with_na_values( tm.assert_series_equal(s_clipped_lower, expected_lower) def test_clip_with_na_args(self): - """Should process np.nan argument as None """ + """Should process np.nan argument as None""" # GH#17276 s = Series([1, 2, 3]) diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index a0e3399bee49f..e100fef3490ba 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -402,7 +402,7 @@ def test_subsets_multiindex_dtype(self): class TestSorted: - """ everything you wanted to test about sorting """ + """everything you wanted to test about sorting""" def test_sort_non_lexsorted(self): # degenerate case where we sort but don't diff --git a/pyproject.toml b/pyproject.toml index 01d28777eb47e..3947856d94d01 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ requires = [ # build-backend = "setuptools.build_meta" [tool.black] -target-version = ['py37', 'py38'] +target-version = ['py37', 'py38', 'py39'] exclude = ''' ( asv_bench/env diff --git a/requirements-dev.txt b/requirements-dev.txt index f454bfd15236c..758ddaebe749a 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -6,7 +6,7 @@ python-dateutil>=2.7.3 pytz asv cython>=0.29.21 -black==20.8b1 +black==21.5b2 cpplint flake8==3.9.2 flake8-bugbear==21.3.2