Skip to content

TYP: stubs for reshape, ops, ops_dispatch, hashing #40455

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 8 commits into from
Mar 17, 2021

Conversation

jbrockmendel
Copy link
Member

manually curated, extra specificity in comments it is supported directly

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Mar 16, 2021
Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

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

Thanks @jbrockmendel generally lgtm

def hash_object_array(
arr: np.ndarray, # np.ndarray[object]
key: str,
encoding: str = "utf8",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
encoding: str = "utf8",
encoding: str = ...,

Comment on lines 3 to 5
REVERSED_NAMES: dict[str, str]
UFUNC_ALIASES: dict[str, str]
DISPATCHED_UFUNCS: set[str]
Copy link
Member

Choose a reason for hiding this comment

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

These are not accessed from python code.

so I don't think is covered by https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#what-to-include

and from https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions

The general rule is that they should be as concise as possible.

so I think we should perhaps not include these.

once we activate ignore_missing_imports = False, we'll know if we missed anything.


side note: for the stub files we could consider activating more of the strictness flags for incomplete function annotations and dynamic typing etc.

DISPATCHED_UFUNCS: set[str]

def maybe_dispatch_ufunc_to_dunder_op(
self, ufunc: np.ufunc, method: str, *inputs, **kwargs
Copy link
Member

Choose a reason for hiding this comment

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

maybe type self, since function is not a method

Copy link
Member Author

Choose a reason for hiding this comment

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

will take some tracking down, since it is called via arraylike.array_ufunc, which doesnt type self


def maybe_convert_bool(
arr: np.ndarray, # np.ndarray[object]
true_values=None,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
true_values=None,
true_values=...,

def maybe_convert_bool(
arr: np.ndarray, # np.ndarray[object]
true_values=None,
false_values=None
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
false_values=None
false_values=...

Comment on lines 8 to 9
binop = Callable[[Any, Any], Any]
bool_op = Callable[[Any, Any], bool]
Copy link
Member

Choose a reason for hiding this comment

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

from https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions

Type variables and aliases you introduce purely for legibility reasons should be prefixed with an underscore to make it obvious to the reader they are not part of the stubbed API.

we normally capitalize as well

@simonjayhawkins simonjayhawkins added this to the 1.3 milestone Mar 16, 2021
@simonjayhawkins
Copy link
Member

manually curated, extra specificity in comments it is supported directly

IIUC The pyright stubs are mainly for the public api. for our internal consistency checking , pandas._libs includes functions that we use internally, so manually curated is probably best for now.

@jbrockmendel
Copy link
Member Author

Will update per suggestions.

IIUC The pyright stubs are mainly for the public api. for our internal consistency checking , pandas._libs includes functions that we use internally, so manually curated is probably best for now.

Following the dev call last month (two months ago?) about stubs I looked over pyright's stubs for _libs and found them not-totally-accurate (mostly Timestamp/Timedelta IIRC), so I plan to do all of these manually.

@simonjayhawkins simonjayhawkins merged commit 3a9c94b into pandas-dev:master Mar 17, 2021
@simonjayhawkins
Copy link
Member

Thanks @jbrockmendel

@jbrockmendel jbrockmendel deleted the typ-libs-3 branch March 17, 2021 14:07
JulianWgs pushed a commit to JulianWgs/pandas that referenced this pull request Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants