Skip to content

STYL: a few cleanups in pyi files #46921

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pandas/_libs/hashtable.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class HashTable:
na_sentinel: int = ...,
na_value: object = ...,
mask=...,
) -> tuple[np.ndarray, npt.NDArray[np.intp],]: ... # np.ndarray[subclass-specific]
) -> tuple[np.ndarray, npt.NDArray[np.intp]]: ... # np.ndarray[subclass-specific]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_unique above only returns tuple if return_inverse is True, which is how it's called from factorize. The return type of _unique is a Union, but these are more easily avoided with overloads in stubs.

I assume that _unique is intended to be private so we probably shouldn't be calling it from outside, so rather than adding overloads could just remove _unique from the stub.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed _unique but haven't yet added overloads to unique as I embarrassingly couldn't find the implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's created from a template. pandas/_libs/hashtable_class_helper.pxi.in

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Would need to first deprecate return_inverse as a positional argument. Can I just use the normal deprecation decorator in cython (or would that have an unintended performance hit).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt HashTable is part of the public API of pandas but is obviously not private to the module as it is used elsewhere. Can probably just make the arguments keyword only without deprecation. (OK as follow-up, for our internal consistency checking, if we do not have any errors reported then not a priority to add overloads if not public)


class Complex128HashTable(HashTable): ...
class Complex64HashTable(HashTable): ...
Expand All @@ -175,7 +175,7 @@ class Int64HashTable(HashTable):
def get_labels_groupby(
self,
values: npt.NDArray[np.int64], # const int64_t[:]
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.int64],]: ...
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.int64]]: ...
def map_keys_to_values(
self,
keys: npt.NDArray[np.int64],
Expand All @@ -198,13 +198,13 @@ def duplicated(
keep: Literal["last", "first", False] = ...,
) -> npt.NDArray[np.bool_]: ...
def mode(
values: np.ndarray, dropna: bool, mask: npt.NDArray[np.bool_] | None = None
values: np.ndarray, dropna: bool, mask: npt.NDArray[np.bool_] | None = ...
) -> np.ndarray: ...
def value_count(
values: np.ndarray,
dropna: bool,
mask: npt.NDArray[np.bool_] | None = None,
) -> tuple[np.ndarray, npt.NDArray[np.int64],]: ... # np.ndarray[same-as-values]
mask: npt.NDArray[np.bool_] | None = ...,
) -> tuple[np.ndarray, npt.NDArray[np.int64]]: ... # np.ndarray[same-as-values]

# arr and values should have same dtype
def ismember(
Expand Down
4 changes: 2 additions & 2 deletions pandas/_libs/tslibs/conversion.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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 = ...,
Expand All @@ -25,5 +25,5 @@ def ensure_timedelta64ns(
) -> np.ndarray: ... # np.ndarray[timedelta64ns]
def datetime_to_datetime64(
values: npt.NDArray[np.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: ...
2 changes: 0 additions & 2 deletions pandas/_libs/tslibs/dtypes.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from enum import Enum

from pandas._libs.tslibs.offsets import BaseOffset

# These are not public API, but are exposed in the .pyi file because they
# are imported in tests.
_attrname_to_abbrevs: dict[str, str]
Expand Down
1 change: 0 additions & 1 deletion pandas/_libs/tslibs/timestamps.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import numpy as np

from pandas._libs.tslibs import (
BaseOffset,
NaTType,
Period,
Tick,
Timedelta,
Expand Down
1 change: 0 additions & 1 deletion pandas/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
- Dtypes
- Misc
"""
# pyright: reportUntypedFunctionDecorator = false

from collections import abc
from datetime import (
Expand Down
29 changes: 8 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,34 +153,21 @@ pythonVersion = "3.8"
typeCheckingMode = "basic"
include = ["pandas", "typings"]
exclude = ["pandas/tests", "pandas/io/clipboard", "pandas/util/version"]
# enable subset of "strict"
reportDuplicateImport = true
reportInvalidStubStatement = true
reportPropertyTypeMismatch = true
reportUntypedClassDecorator = true
reportUntypedFunctionDecorator = true
reportUntypedNamedTuple = true
# disable subset of "basic"
reportGeneralTypeIssues = false
reportConstantRedefinition = false
reportFunctionMemberAccess = false
reportImportCycles = false
reportIncompatibleMethodOverride = false
reportIncompatibleVariableOverride = false
reportMissingModuleSource = false
reportMissingParameterType = false
reportMissingTypeArgument = false
reportMissingTypeStubs = false
reportOptionalCall = false
reportOptionalIterable = false
reportOptionalMemberAccess = false
reportOptionalOperand = false
reportOptionalSubscript = false
reportPrivateImportUsage = false
reportPrivateUsage = false
reportUnboundVariable = false
reportUnknownArgumentType = false
reportUnknownLambdaType = false
reportUnknownMemberType = false
reportUnknownParameterType = false
reportUnknownVariableType = false
reportUnnecessaryComparison = false
reportUnnecessaryIsInstance = false
reportUnsupportedDunderAll = false
reportUntypedBaseClass = false
reportUnusedClass = false
reportUnusedFunction = false
reportUnusedImport = false
reportUnusedVariable = false