From e325835cae10bc153315daf0d3720df31b797bed Mon Sep 17 00:00:00 2001 From: VirosaLi <2EkF8qUgpNkj> Date: Tue, 8 Dec 2020 17:42:33 -0600 Subject: [PATCH 01/13] Add py39 target for Black --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2b78147e9294d..17baee33a6ca8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ requires = [ ] [tool.black] -target-version = ['py37', 'py38'] +target-version = ['py37', 'py38', 'py39'] exclude = ''' ( asv_bench/env From fed6c3add0114af5ad37116ae30954e2e1670c81 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 11 May 2021 19:40:12 -0500 Subject: [PATCH 02/13] bump black version --- .pre-commit-config.yaml | 2 +- .../development/contributing_codebase.rst | 2 +- environment.yml | 2 +- pandas/_config/config.py | 8 +- pandas/_libs/algos.pyi | 396 +++++++++++------- pandas/_libs/arrays.pyi | 11 - pandas/_libs/groupby.pyi | 115 +++-- pandas/_libs/hashtable.pyi | 53 +-- pandas/_libs/index.pyi | 30 +- pandas/_libs/internals.pyi | 27 +- pandas/_libs/join.pyi | 111 ++--- pandas/_libs/lib.pyi | 100 ++--- pandas/_libs/ops.pyi | 26 +- pandas/_libs/parsers.pyi | 10 +- pandas/_libs/reshape.pyi | 13 +- pandas/_libs/testing.pyi | 18 +- pandas/_libs/tslib.pyi | 9 +- pandas/_libs/tslibs/ccalendar.pyi | 1 - pandas/_libs/tslibs/conversion.pyi | 18 +- pandas/_libs/tslibs/dtypes.pyi | 12 - pandas/_libs/tslibs/fields.pyi | 23 +- pandas/_libs/tslibs/nattype.pyi | 25 -- pandas/_libs/tslibs/parsing.pyi | 40 +- pandas/_libs/tslibs/period.pyi | 40 +- pandas/_libs/tslibs/strptime.pyi | 3 +- pandas/_libs/tslibs/timedeltas.pyi | 22 +- pandas/_libs/tslibs/timestamps.pyi | 58 ++- pandas/_libs/tslibs/timezones.pyi | 13 +- pandas/_libs/tslibs/tzconversion.pyi | 2 - pandas/_libs/tslibs/vectorized.pyi | 8 - pandas/_libs/window/aggregations.pyi | 24 +- pandas/_libs/window/indexers.pyi | 9 +- pandas/_libs/writers.pyi | 4 - pandas/_testing/__init__.py | 4 +- pandas/conftest.py | 2 +- pandas/core/algorithms.py | 2 +- pandas/core/apply.py | 12 +- pandas/core/arrays/categorical.py | 2 +- pandas/core/arrays/masked.py | 4 +- pandas/core/arrays/sparse/scipy_sparse.py | 2 +- pandas/core/computation/expr.py | 4 +- pandas/core/computation/expressions.py | 2 +- pandas/core/computation/pytables.py | 30 +- pandas/core/dtypes/cast.py | 4 +- pandas/core/dtypes/common.py | 2 +- pandas/core/dtypes/dtypes.py | 2 +- pandas/core/generic.py | 10 +- pandas/core/groupby/ops.py | 6 +- pandas/core/indexes/category.py | 2 +- pandas/core/indexes/multi.py | 10 +- pandas/core/indexes/range.py | 6 +- pandas/core/internals/array_manager.py | 4 +- pandas/core/internals/blocks.py | 26 +- pandas/core/internals/managers.py | 18 +- pandas/core/nanops.py | 4 +- pandas/core/ops/__init__.py | 2 +- pandas/core/reshape/merge.py | 8 +- pandas/core/reshape/tile.py | 2 +- pandas/io/formats/format.py | 6 +- pandas/io/parquet.py | 2 +- pandas/io/parsers/readers.py | 2 +- pandas/io/pytables.py | 144 +++---- pandas/io/sas/sas_xport.py | 2 +- pandas/io/sql.py | 2 +- pandas/io/stata.py | 6 +- pandas/tests/arithmetic/test_period.py | 4 +- pandas/tests/base/test_constructors.py | 2 +- pandas/tests/dtypes/test_common.py | 4 +- pandas/tests/extension/base/reduce.py | 2 +- pandas/tests/frame/methods/test_clip.py | 2 +- pandas/tests/generic/test_generic.py | 2 +- .../generic/test_label_or_level_utils.py | 8 +- pandas/tests/indexing/common.py | 6 +- pandas/tests/indexing/test_coercion.py | 10 +- pandas/tests/indexing/test_indexing.py | 2 +- pandas/tests/internals/test_internals.py | 2 +- .../tests/io/generate_legacy_storage_files.py | 2 +- pandas/tests/io/pytables/common.py | 2 +- pandas/tests/io/pytables/conftest.py | 2 +- pandas/tests/plotting/frame/test_frame.py | 2 +- pandas/tests/plotting/test_misc.py | 2 +- pandas/tests/resample/test_base.py | 2 +- pandas/tests/resample/test_deprecated.py | 2 +- pandas/tests/reshape/merge/test_merge_asof.py | 8 +- pandas/tests/series/methods/test_clip.py | 2 +- pandas/tests/test_multilevel.py | 2 +- requirements-dev.txt | 2 +- 87 files changed, 666 insertions(+), 975 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2f46190ef5eb7..759250a317c16 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.5b1 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..6b205d36fbcfe 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.5b1 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 30fa7c0dea696..550924de91624 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - cython>=0.29.21 # code checks - - black=20.8b1 + - black=21.5b1 - cpplint - flake8=3.9.1 - flake8-bugbear=21.3.2 # used by flake8, find likely bugs diff --git a/pandas/_config/config.py b/pandas/_config/config.py index 455f800073c15..ed48ff7ae08c6 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..a2d028250eb51 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: ... def nancorr_spearman( mat: np.ndarray, # ndarray[float64_t, ndim=2] minp: int = 1, -) -> np.ndarray: # np.ndarray[np.float64, ndim=2] - ... - - +) -> np.ndarray: ... def nancorr_kendall( mat: np.ndarray, # ndarray[float64_t, ndim=2] minp: int = 1, -) -> np.ndarray: # np.ndarray[float64, ndim=2] - ... +) -> np.ndarray: ... # ---------------------------------------------------------------------- @@ -92,58 +75,40 @@ 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: ... 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]: - ... + arr: np.ndarray, timelike: bool # ndarray[algos_t, ndim=1] +) -> tuple[bool, bool, bool]: ... # ---------------------------------------------------------------------- # rank_1d, rank_2d @@ -155,7 +120,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 +129,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 +138,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 +145,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..39e5fbfea9dd1 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[:] values ) -> 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 9dbc47f1d40f7..c824aebbdffac 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -18,19 +18,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: ... @@ -38,13 +34,11 @@ 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_period_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): ... @@ -52,18 +46,16 @@ 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_multiget(mapping: dict, keys: np.ndarray, default=np.nan) -> np.ndarray: ... - 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] @@ -73,7 +65,6 @@ def maybe_convert_objects( convert_timedelta: bool = ..., convert_to_nullable_integer: Literal[False] = ..., ) -> np.ndarray: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -83,7 +74,6 @@ def maybe_convert_objects( convert_timedelta: bool = ..., convert_to_nullable_integer: Literal[True] = ..., ) -> ArrayLike: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -93,7 +83,6 @@ def maybe_convert_objects( convert_timedelta: bool = ..., convert_to_nullable_integer: Literal[False] = ..., ) -> ArrayLike: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -103,7 +92,6 @@ def maybe_convert_objects( convert_timedelta: bool = ..., convert_to_nullable_integer: Literal[True] = ..., ) -> ArrayLike: ... - @overload def maybe_convert_objects( objects: np.ndarray, # np.ndarray[object] @@ -113,7 +101,6 @@ def maybe_convert_objects( convert_timedelta: bool = ..., convert_to_nullable_integer: bool = ..., ) -> ArrayLike: ... - @overload def maybe_convert_numeric( values: np.ndarray, # np.ndarray[object] @@ -122,7 +109,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] @@ -141,54 +127,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] -) -> str: ... - +def infer_datetimelike_array(arr: np.ndarray) -> str: ... # np.ndarray[object] 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 clean_index_list(obj: list) -> tuple[ - list | np.ndarray, # np.ndarray[object] | np.ndarray[np.int64] - bool, -]: ... - +def clean_index_list( + obj: list, +) -> tuple[list | np.ndarray, bool,]: ... # np.ndarray[object] | np.ndarray[np.int64] # ----------------------------------------------------------------- # 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], @@ -197,57 +166,38 @@ 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] 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..10c8a819b9b78 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 0f81dcb4b2df1..60da50d203f15 100644 --- a/pandas/_libs/tslibs/nattype.pyi +++ b/pandas/_libs/tslibs/nattype.pyi @@ -1,4 +1,3 @@ - from datetime import datetime import numpy as np @@ -11,11 +10,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 @@ -30,7 +27,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 @@ -47,81 +43,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: ... @@ -129,7 +105,6 @@ class NaTType(datetime): def microseconds(self) -> float: ... @property def nanoseconds(self) -> float: ... - # inject Period properties @property def qyear(self) -> float: ... 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/strptime.pyi b/pandas/_libs/tslibs/strptime.pyi index 3748c169bb1c6..1b4376ceadebe 100644 --- a/pandas/_libs/tslibs/strptime.pyi +++ b/pandas/_libs/tslibs/strptime.pyi @@ -6,6 +6,7 @@ def array_strptime( values: np.ndarray, # np.ndarray[object] fmt: Optional[str], exact: bool = True, - errors: str = "raise" + errors: str = "raise", ) -> tuple[np.ndarray, np.ndarray]: ... + # first ndarray is M8[ns], second is object ndarray of Optional[tzinfo] 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 8728b700a1f6d..4ed37abe3f5b5 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -26,10 +26,8 @@ from pandas._libs.tslibs import ( _S = TypeVar("_S") - def integer_op_not_supported(obj) -> None: ... - class Timestamp(datetime): min: ClassVar[Timestamp] max: ClassVar[Timestamp] @@ -40,9 +38,15 @@ class Timestamp(datetime): # error: "__new__" must return a class instance (got "Union[Timestamp, NaTType]") def __new__( # type: ignore[misc] cls: Type[_S], - ts_input: int | np.integer | float | str | _date | datetime | np.datetime64 = ..., + ts_input: int + | np.integer + | float + | str + | _date + | datetime + | np.datetime64 = ..., freq=..., - tz: str | _tzinfo | None | int= ..., + tz: str | _tzinfo | None | int = ..., unit=..., year: int | None = ..., month: int | None = ..., @@ -54,9 +58,8 @@ class Timestamp(datetime): nanosecond: int | None = ..., tzinfo: _tzinfo | None = ..., *, - fold: int | None= ..., + fold: int | None = ..., ) -> _S | NaTType: ... - @property def year(self) -> int: ... @property @@ -75,10 +78,8 @@ class Timestamp(datetime): def tzinfo(self) -> Optional[_tzinfo]: ... @property def tz(self) -> Optional[_tzinfo]: ... - @property def fold(self) -> int: ... - @classmethod def fromtimestamp(cls: Type[_S], t: float, tz: Optional[_tzinfo] = ...) -> _S: ... @classmethod @@ -87,7 +88,6 @@ class Timestamp(datetime): def today(cls: Type[_S]) -> _S: ... @classmethod def fromordinal(cls: Type[_S], n: int) -> _S: ... - if sys.version_info >= (3, 8): @classmethod def now(cls: Type[_S], tz: _tzinfo | str | None = ...) -> _S: ... @@ -98,28 +98,23 @@ class Timestamp(datetime): @overload @classmethod def now(cls, tz: _tzinfo) -> datetime: ... - @classmethod def utcnow(cls: Type[_S]) -> _S: ... @classmethod - def combine(cls, date: _date, time: _time, tzinfo: Optional[_tzinfo] = ...) -> datetime: ... - + def combine( + cls, date: _date, time: _time, tzinfo: Optional[_tzinfo] = ... + ) -> datetime: ... @classmethod def fromisoformat(cls: Type[_S], date_string: str) -> _S: ... - def strftime(self, fmt: str) -> str: ... def __format__(self, fmt: str) -> str: ... - def toordinal(self) -> int: ... def timetuple(self) -> struct_time: ... - def timestamp(self) -> float: ... - def utctimetuple(self) -> struct_time: ... def date(self) -> _date: ... def time(self) -> _time: ... def timetz(self) -> _time: ... - def replace( self, year: int = ..., @@ -133,22 +128,17 @@ class Timestamp(datetime): *, fold: int = ..., ) -> datetime: ... - if sys.version_info >= (3, 8): def astimezone(self: _S, tz: Optional[_tzinfo] = ...) -> _S: ... else: def astimezone(self, tz: Optional[_tzinfo] = ...) -> datetime: ... - def ctime(self) -> str: ... def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... - @classmethod def strptime(cls, date_string: str, format: str) -> datetime: ... - def utcoffset(self) -> Optional[timedelta]: ... def tzname(self) -> Optional[str]: ... def dst(self) -> Optional[timedelta]: ... - def __le__(self, other: datetime) -> bool: ... # type: ignore def __lt__(self, other: datetime) -> bool: ... # type: ignore def __ge__(self, other: datetime) -> bool: ... # type: ignore @@ -163,12 +153,10 @@ class Timestamp(datetime): def __sub__(self, other: datetime) -> timedelta: ... @overload def __sub__(self, other: timedelta) -> datetime: ... - def __hash__(self) -> int: ... def weekday(self) -> int: ... def isoweekday(self) -> int: ... def isocalendar(self) -> tuple[int, int, int]: ... - @property def is_leap_year(self) -> bool: ... @property @@ -183,23 +171,25 @@ class Timestamp(datetime): def is_quarter_end(self) -> bool: ... @property def is_year_end(self) -> bool: ... - def to_pydatetime(self, warn: bool = ...) -> datetime: ... def to_datetime64(self) -> np.datetime64: ... def to_period(self, freq) -> Period: ... def to_julian_date(self) -> np.float64: ... - @property def asm8(self) -> np.datetime64: ... - def tz_convert(self: _S, tz) -> _S: ... - # TODO: could return NaT? - def tz_localize(self: _S, tz, ambiguous: str = ..., nonexistent: str = ...) -> _S: ... - + def tz_localize( + self: _S, tz, ambiguous: str = ..., nonexistent: str = ... + ) -> _S: ... def normalize(self: _S) -> _S: ... - # TODO: round/floor/ceil could return NaT? - def round(self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...) -> _S: ... - def floor(self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...) -> _S: ... - def ceil(self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ...) -> _S: ... + def round( + self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ... + ) -> _S: ... + def floor( + self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ... + ) -> _S: ... + def ceil( + self: _S, freq, ambiguous: bool | str = ..., nonexistent: str = ... + ) -> _S: ... diff --git a/pandas/_libs/tslibs/timezones.pyi b/pandas/_libs/tslibs/timezones.pyi index 04a1b391dc30a..fc03e4e4c68da 100644 --- a/pandas/_libs/tslibs/timezones.pyi +++ b/pandas/_libs/tslibs/timezones.pyi @@ -13,20 +13,17 @@ import numpy as np # imported from dateutil.tz dateutil_gettz: Callable[[str], tzinfo] - def tz_standardize(tz: tzinfo) -> tzinfo: ... - def tz_compare(start: Optional[tzinfo], end: Optional[tzinfo]) -> bool: ... - def infer_tzinfo( - start: Optional[datetime], end: Optional[datetime], + start: Optional[datetime], + end: Optional[datetime], ) -> Optional[tzinfo]: ... # ndarrays returned are both int64_t def get_dst_info(tz: tzinfo) -> tuple[np.ndarray, np.ndarray, str]: ... - -def maybe_get_tz(tz: Optional[Union[str, int, np.int64, tzinfo]]) -> Optional[tzinfo]: ... - +def maybe_get_tz( + tz: Optional[Union[str, int, np.int64, tzinfo]] +) -> Optional[tzinfo]: ... def get_timezone(tz: tzinfo) -> Union[tzinfo, str]: ... - def is_utc(tz: Optional[tzinfo]) -> bool: ... diff --git a/pandas/_libs/tslibs/tzconversion.pyi b/pandas/_libs/tslibs/tzconversion.pyi index f47885a2e3306..219548474f9e6 100644 --- a/pandas/_libs/tslibs/tzconversion.pyi +++ b/pandas/_libs/tslibs/tzconversion.pyi @@ -14,9 +14,7 @@ def tz_convert_from_utc( vals: np.ndarray, # const int64_t[:] tz: tzinfo, ) -> np.ndarray: ... # np.ndarray[np.int64] - def tz_convert_from_utc_single(val: np.int64, tz: tzinfo) -> np.int64: ... - def tz_localize_to_utc( vals: np.ndarray, # np.ndarray[np.int64] tz: Optional[tzinfo], diff --git a/pandas/_libs/tslibs/vectorized.pyi b/pandas/_libs/tslibs/vectorized.pyi index 6ed1e10ef2353..ec8b33cd33d2c 100644 --- a/pandas/_libs/tslibs/vectorized.pyi +++ b/pandas/_libs/tslibs/vectorized.pyi @@ -18,26 +18,18 @@ def dt64arr_to_periodarr( freq: int, tz: Optional[tzinfo], ) -> np.ndarray: ... # np.ndarray[np.int64, ndim=1] - - def is_date_array_normalized( stamps: np.ndarray, # const int64_t[:] tz: Optional[tzinfo] = None, ) -> bool: ... - - def normalize_i8_timestamps( stamps: np.ndarray, # const int64_t[:] tz: Optional[tzinfo], ) -> np.ndarray: ... # np.ndarray[np.int64] - - def get_resolution( stamps: np.ndarray, # const int64_t[:] tz: Optional[tzinfo] = None, ) -> Resolution: ... - - def ints_to_pydatetime( arr: np.ndarray, # const int64_t[:}] tz: Optional[tzinfo] = None, 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 aaf58f1fcb150..5f7981bc71e15 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -271,7 +271,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 @@ -279,7 +279,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 7b29c41ef70f5..cf04355ec0cc4 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -573,7 +573,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 f8f5e5e05bc35..954fc12b7cf1c 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1840,7 +1840,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 9d3437fe08b24..64f196796bf0a 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: @@ -630,7 +630,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() @@ -724,7 +724,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): """ @@ -858,7 +858,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 @@ -941,7 +941,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 @@ -960,7 +960,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 26c582561cd3d..d5aaecb77e4ba 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -1650,7 +1650,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 02660539f4981..4f90a83c6b212 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -567,7 +567,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): @@ -591,7 +591,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 2f87e0bcce70a..863832679efb0 100644 --- a/pandas/core/computation/expressions.py +++ b/pandas/core/computation/expressions.py @@ -73,7 +73,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 46dc97214e2f6..be6d3ca1b516f 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -116,7 +116,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)): @@ -937,7 +937,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 593e42f7ed749..35bef09de1799 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -157,7 +157,7 @@ def ensure_python_int(value: Union[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 c5efd8f77495c..b86fab6a226bf 100644 --- a/pandas/core/dtypes/dtypes.py +++ b/pandas/core/dtypes/dtypes.py @@ -110,7 +110,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 0d39f13afc426..2d9e5957c1e1d 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) @@ -4012,7 +4012,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 @@ -4868,7 +4868,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()): @@ -5587,7 +5587,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 3045451974ee7..f7a61a536c96d 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -820,7 +820,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 @@ -854,7 +854,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: @@ -1098,7 +1098,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 e835990eb8d89..2b45fab12b112 100644 --- a/pandas/core/indexes/category.py +++ b/pandas/core/indexes/category.py @@ -630,7 +630,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 f4e34e592954d..513bccf3deee3 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -1212,11 +1212,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 @@ -1235,7 +1235,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 @@ -1251,7 +1251,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: @@ -1606,7 +1606,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 8a91ba22fcba1..9e00cd90ce45c 100644 --- a/pandas/core/indexes/range.py +++ b/pandas/core/indexes/range.py @@ -174,7 +174,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 @@ -198,7 +198,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)] @@ -351,7 +351,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 0541b76b377f7..35c5585d47c67 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -432,7 +432,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( @@ -461,7 +461,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 92f9d803d1ebe..ad5a3b714d6de 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -166,7 +166,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 @@ -259,7 +259,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 @@ -288,7 +288,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] @@ -527,7 +527,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] @@ -614,7 +614,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) @@ -635,14 +635,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() @@ -1155,12 +1155,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 @@ -1673,7 +1673,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 @@ -1769,7 +1769,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 @@ -1985,7 +1985,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): @@ -2025,7 +2025,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 ea31f9663cffe..a9d7b2038e61d 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 @@ -1501,7 +1501,7 @@ def _interleave( class SingleBlockManager(BaseBlockManager, SingleDataManager): - """ manage a single block with """ + """manage a single block with""" ndim = 1 _is_consolidated = True @@ -1595,12 +1595,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: @@ -1758,7 +1758,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: @@ -1884,7 +1884,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 2c31e45d0b4e1..556e02ad9fd51 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): @@ -350,7 +350,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 f8085b2bab1ed..dffd5628e0bd3 100644 --- a/pandas/core/reshape/merge.py +++ b/pandas/core/reshape/merge.py @@ -927,7 +927,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 @@ -1688,7 +1688,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): @@ -1879,10 +1879,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 7b9c3883d74e3..a21950fae6816 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 9d653c9a5f97c..4cd79ecfd9192 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): @@ -1739,7 +1739,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 @@ -1753,7 +1753,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 5ad014a334c27..f05dd53dbf262 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 55e3e14a0969d..dc6f902fc86fe 100644 --- a/pandas/io/parsers/readers.py +++ b/pandas/io/parsers/readers.py @@ -1144,7 +1144,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[Union[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 10d55053d5bc6..470c42aee0869 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): @@ -1491,7 +1491,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 @@ -1507,7 +1507,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") @@ -1624,7 +1624,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()] @@ -1641,7 +1641,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)): @@ -2019,7 +2019,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 @@ -2036,7 +2036,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"] @@ -2047,7 +2047,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 @@ -2092,7 +2092,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 @@ -2105,12 +2105,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): @@ -2141,7 +2141,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 @@ -2200,17 +2200,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) @@ -2225,13 +2225,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: @@ -2330,7 +2330,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"] @@ -2347,7 +2347,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 @@ -2388,7 +2388,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" @@ -2419,7 +2419,7 @@ def shape(self): @property def cvalues(self): - """ return my cython values """ + """return my cython values""" return self.data def validate_attr(self, append): @@ -2537,7 +2537,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 @@ -2545,7 +2545,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 @@ -2572,7 +2572,7 @@ def get_atom_timedelta64(cls, shape): class GenericDataIndexableCol(DataIndexableCol): - """ represent a generic pytables data column """ + """represent a generic pytables data column""" pass @@ -2621,7 +2621,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(".")) @@ -2636,7 +2636,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: @@ -2647,7 +2647,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) @@ -2684,16 +2684,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 @@ -2705,13 +2705,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): @@ -2754,7 +2754,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()} @@ -2836,12 +2836,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: @@ -2851,7 +2851,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) @@ -3008,7 +3008,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) @@ -3296,7 +3296,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}]" @@ -3314,14 +3314,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 @@ -3377,7 +3377,7 @@ 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""" # error: Incompatible return value type (got "number", expected "int") return np.prod( # type: ignore[return-value] [i.cvalues.shape[0] for i in self.index_axes] @@ -3385,7 +3385,7 @@ def nrows_expected(self) -> int: @property def is_exists(self) -> bool: - """ has this table been created """ + """has this table been created""" return "table" in self.group @property @@ -3394,7 +3394,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 @@ -3411,7 +3411,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 @@ -3429,7 +3429,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"} @@ -3445,16 +3445,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" @@ -3482,13 +3482,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() @@ -3501,7 +3501,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 {} @@ -3513,7 +3513,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]) @@ -3543,7 +3543,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 @@ -3735,7 +3735,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): @@ -4070,7 +4070,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) @@ -4134,7 +4134,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) @@ -4259,7 +4259,7 @@ def write(self, **kwargs): class AppendableTable(Table): - """ support the new appendable table formats """ + """support the new appendable table formats""" table_type = "appendable" @@ -4488,7 +4488,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" @@ -4501,7 +4501,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 @@ -4588,7 +4588,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" @@ -4604,7 +4604,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) @@ -4637,13 +4637,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 @@ -4654,7 +4654,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" @@ -4671,7 +4671,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 = [] @@ -4682,7 +4682,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 @@ -4720,7 +4720,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 @@ -4787,7 +4787,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 @@ -5235,7 +5235,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 a347e7a99be8b..4f7e1bcca8a7a 100644 --- a/pandas/io/sql.py +++ b/pandas/io/sql.py @@ -1354,7 +1354,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 f1747f94a7ea8..2928c1837c15e 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 616f46624bfd7..cf9acadc7a6dd 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -24,12 +24,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 6525109da4394..fecd16b5e4853 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 771d31aa6865b..2fda56827d771 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 6f4949267c00c..a0d62f1fa782d 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -79,7 +79,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) @@ -270,7 +270,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) @@ -364,7 +364,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) @@ -552,7 +552,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) @@ -866,7 +866,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 0c20622311e1f..aba6775d39da0 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 08dba5aa76a2f..6d2f541e353bb 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 fdb3a7872ad67..8ae3abf903d57 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 6185fe6c54fa4..d37d28b5c9c3f 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/requirements-dev.txt b/requirements-dev.txt index 3e421c7715566..848b0d23a68d6 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.5b1 cpplint flake8==3.9.1 flake8-bugbear==21.3.2 From af6632fbc8804f4ad7c373285f3dbd1a09842b60 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 11 May 2021 19:51:25 -0500 Subject: [PATCH 03/13] bump black version --- environment.yml | 2 +- requirements-dev.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 550924de91624..99eaa4f62afd4 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - cython>=0.29.21 # code checks - - black=21.5b1 + - black=21.5b0 - cpplint - flake8=3.9.1 - flake8-bugbear=21.3.2 # used by flake8, find likely bugs diff --git a/requirements-dev.txt b/requirements-dev.txt index 848b0d23a68d6..e00be4354a44b 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==21.5b1 +black==21.5b0 cpplint flake8==3.9.1 flake8-bugbear==21.3.2 From b92b327ab53a3ea1c03c8aca96c977d62db7e60b Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 11 May 2021 19:53:58 -0500 Subject: [PATCH 04/13] bump black version --- .pre-commit-config.yaml | 2 +- doc/source/development/contributing_codebase.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 759250a317c16..0bf1935e2b774 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: 21.5b1 + rev: 21.5b0 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 6b205d36fbcfe..411b65fdc9449 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 21.5b1 as previous versions are not compatible +You should use a ``black`` version 21.5b0 as previous versions are not compatible with the pandas codebase. One caveat about ``git diff upstream/master -u -- "*.py" | flake8 --diff``: this From 5986521cb9c15f3b324e5795d512ff2a39d07dcf Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 18 May 2021 13:30:45 -0500 Subject: [PATCH 05/13] fix comments --- pandas/_libs/algos.pyi | 6 +++--- pandas/_libs/tslibs/conversion.pyi | 4 ++-- pandas/_libs/window/indexers.pyi | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index a2d028250eb51..96dfd81153c1d 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -50,15 +50,15 @@ def nancorr( mat: np.ndarray, # const float64_t[:, :] cov: bool = False, minp=None, -) -> np.ndarray: ... +) -> 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: ... # ndarray[float64_t, ndim=2] def nancorr_kendall( mat: np.ndarray, # ndarray[float64_t, ndim=2] minp: int = 1, -) -> np.ndarray: ... +) -> np.ndarray: ... # ndarray[float64_t, ndim=2] # ---------------------------------------------------------------------- diff --git a/pandas/_libs/tslibs/conversion.pyi b/pandas/_libs/tslibs/conversion.pyi index 10c8a819b9b78..e74a56a519c5a 100644 --- a/pandas/_libs/tslibs/conversion.pyi +++ b/pandas/_libs/tslibs/conversion.pyi @@ -12,7 +12,7 @@ class OutOfBoundsTimedelta(ValueError): ... def precision_from_unit( unit: str, -) -> tuple[int, int,]: ... # int64_t +) -> tuple[int, int,]: ... # (int64_t, _) def ensure_datetime64ns( arr: np.ndarray, # np.ndarray[datetime64[ANY]] copy: bool = ..., @@ -23,5 +23,5 @@ def ensure_timedelta64ns( ) -> np.ndarray: ... # np.ndarray[timedelta64ns] def datetime_to_datetime64( values: np.ndarray, # np.ndarray[object] -) -> tuple[np.ndarray, tzinfo | None,]: ... # np.ndarray[dt64ns] +) -> tuple[np.ndarray, tzinfo | None,]: ... # (np.ndarray[dt64ns], _) def localize_pydatetime(dt: datetime, tz: tzinfo | None) -> datetime: ... diff --git a/pandas/_libs/window/indexers.pyi b/pandas/_libs/window/indexers.pyi index 2dea9362228e5..f65deae6fdf55 100644 --- a/pandas/_libs/window/indexers.pyi +++ b/pandas/_libs/window/indexers.pyi @@ -7,4 +7,7 @@ def calculate_variable_window_bounds( center: bool, closed: str | None, index: np.ndarray, # const int64_t[:] -) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64] +) -> tuple[ + np.ndarray, + np.ndarray, +]: ... # (np.ndarray[np.int64] # np.ndarray[np.int64]) From 16071c42e6785532d2b7bd141e47b71fbfa497f2 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 1 Jun 2021 13:17:43 -0500 Subject: [PATCH 06/13] update black version --- .pre-commit-config.yaml | 2 +- doc/source/development/contributing_codebase.rst | 2 +- environment.yml | 2 +- pandas/_libs/lib.pyi | 4 +--- pandas/_libs/tslibs/nattype.pyi | 13 ++++--------- requirements-dev.txt | 2 +- 6 files changed, 9 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b47f4a8a5cfb3..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: 21.5b0 + 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 411b65fdc9449..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 21.5b0 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 332b8532727b2..1eccbf978c2d1 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - cython>=0.29.21 # code checks - - black=21.5b0 + - black=21.5b2 - cpplint - flake8=3.9.2 - flake8-bugbear=21.3.2 # used by flake8, find likely bugs diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index 5a9c0edd895bc..32186afcb53ba 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -136,11 +136,9 @@ 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, diff --git a/pandas/_libs/tslibs/nattype.pyi b/pandas/_libs/tslibs/nattype.pyi index 4f7692d1a49ff..22e6395a1fe99 100644 --- a/pandas/_libs/tslibs/nattype.pyi +++ b/pandas/_libs/tslibs/nattype.pyi @@ -114,31 +114,26 @@ class NaTType(datetime): # 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/requirements-dev.txt b/requirements-dev.txt index 7f07c499e11fe..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==21.5b0 +black==21.5b2 cpplint flake8==3.9.2 flake8-bugbear==21.3.2 From c09405faf48f8e67339c34683c59a03285211b60 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Sun, 6 Jun 2021 15:42:53 -0500 Subject: [PATCH 07/13] rebase --- pandas/_libs/lib.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/_libs/lib.pyi b/pandas/_libs/lib.pyi index 08b44d1e3e2ae..39a55724a356c 100644 --- a/pandas/_libs/lib.pyi +++ b/pandas/_libs/lib.pyi @@ -48,7 +48,6 @@ 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: ... @@ -174,7 +173,6 @@ 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: ... # ----------------------------------------------------------------- From cc37bf31937e909a9fc0665cd39cd7d281fb8e01 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 8 Jun 2021 11:17:04 -0500 Subject: [PATCH 08/13] fix typo in comment --- pandas/_libs/hashtable.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/hashtable.pyi b/pandas/_libs/hashtable.pyi index 39e5fbfea9dd1..5a1b98b190dbc 100644 --- a/pandas/_libs/hashtable.pyi +++ b/pandas/_libs/hashtable.pyi @@ -123,7 +123,7 @@ class HashTable: def map( self, keys: np.ndarray, # np.ndarray[subclass-specific] - values: np.ndarray, # const int64_t[:] values + values: np.ndarray, # const int64_t[:] ) -> None: ... def map_locations( self, From d5f65abde9ed381d4734b542ef0119d81a5d16ce Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 8 Jun 2021 11:27:54 -0500 Subject: [PATCH 09/13] reformat --- pandas/_libs/algos.pyi | 2 +- pandas/_libs/tslibs/timestamps.pyi | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index 96dfd81153c1d..660f2fcb50d29 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -95,7 +95,7 @@ def backfill( old: np.ndarray, # ndarray[algos_t] new: np.ndarray, # ndarray[algos_t] limit=None, -) -> np.ndarray: ... +) -> np.ndarray: ... # np.ndarray[np.intp, ndim=1] def backfill_inplace( values: np.ndarray, # algos_t[:] mask: np.ndarray, # uint8_t[:] diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index d25addef0cb1c..623122c34711a 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 From bc1bdc30eb16a732103dbba26d49531f0614f063 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 8 Jun 2021 12:51:54 -0500 Subject: [PATCH 10/13] fix error --- pandas/_libs/tslibs/timestamps.pyi | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyi b/pandas/_libs/tslibs/timestamps.pyi index 623122c34711a..ff6b18835322e 100644 --- a/pandas/_libs/tslibs/timestamps.pyi +++ b/pandas/_libs/tslibs/timestamps.pyi @@ -137,9 +137,9 @@ class Timestamp(datetime): def isoformat(self, sep: str = ..., timespec: str = ...) -> str: ... @classmethod def strptime(cls, date_string: str, format: str) -> datetime: ... - def utcoffset(self) -> Optional[timedelta]: ... - def tzname(self) -> Optional[str]: ... - def dst(self) -> Optional[timedelta]: ... + def utcoffset(self) -> timedelta | None: ... + def tzname(self) -> str | None: ... + def dst(self) -> timedelta | None: ... def __le__(self, other: datetime) -> bool: ... # type: ignore def __lt__(self, other: datetime) -> bool: ... # type: ignore def __ge__(self, other: datetime) -> bool: ... # type: ignore From 5d8a3c98da2220cb10852eb54b684b3213bf8707 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 8 Jun 2021 19:43:43 -0500 Subject: [PATCH 11/13] add comment back --- pandas/_libs/algos.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/algos.pyi b/pandas/_libs/algos.pyi index 660f2fcb50d29..d0f664c323a89 100644 --- a/pandas/_libs/algos.pyi +++ b/pandas/_libs/algos.pyi @@ -107,7 +107,8 @@ def backfill_2d_inplace( limit=None, ) -> None: ... def is_monotonic( - arr: np.ndarray, timelike: bool # ndarray[algos_t, ndim=1] + arr: np.ndarray, # ndarray[algos_t, ndim=1] + timelike: bool, ) -> tuple[bool, bool, bool]: ... # ---------------------------------------------------------------------- From 41dbc41e6222e6e4171cdf56ba3a5443eebeea7f Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Tue, 8 Jun 2021 19:54:28 -0500 Subject: [PATCH 12/13] add comment back --- pandas/_libs/window/indexers.pyi | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pandas/_libs/window/indexers.pyi b/pandas/_libs/window/indexers.pyi index f65deae6fdf55..2dea9362228e5 100644 --- a/pandas/_libs/window/indexers.pyi +++ b/pandas/_libs/window/indexers.pyi @@ -7,7 +7,4 @@ def calculate_variable_window_bounds( center: bool, closed: str | None, index: np.ndarray, # const int64_t[:] -) -> tuple[ - np.ndarray, - np.ndarray, -]: ... # (np.ndarray[np.int64] # np.ndarray[np.int64]) +) -> tuple[np.ndarray, np.ndarray,]: ... # np.ndarray[np.int64] # np.ndarray[np.int64] From c3ea1bdc8c0e22e8e44b6978d99f03490b8869a1 Mon Sep 17 00:00:00 2001 From: Fangchen Li Date: Wed, 9 Jun 2021 13:35:01 -0500 Subject: [PATCH 13/13] run black again --- pandas/io/parsers/readers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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))