-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TYP: parsers.pyi #40508
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
TYP: parsers.pyi #40508
Conversation
jbrockmendel
commented
Mar 18, 2021
- closes #xxxx
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jbrockmendel only partly reviewed. comments so far.
pandas/_libs/window/indexers.pyi
Outdated
window_size: int, # int64_t | ||
min_periods: object, | ||
center: object, | ||
closed: object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
str
pandas/_libs/window/indexers.pyi
Outdated
min_periods: object, | ||
center: object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps leave untyped for now unless these can accept any type. (although I accept that these are unused so could in theory accept anything without raising TypeError)
from https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions
When adding type hints, avoid using the Any type when possible. Reserve the use of Any for when:
the correct type cannot be expressed in the current type system; and
to avoid Union returns (see above).
Note that Any is not the correct type to use if you want to indicate that some function can accept literally anything: in those cases use object instead.
so object is the correct type, unless we want to make these consistent with get_window_bounds signature
pandas/_libs/parsers.pyi
Outdated
|
||
def close(self) -> None: ... | ||
|
||
def read(self, rows: int | None = None) -> dict[int, ArrayLike]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def read(self, rows: int | None = None) -> dict[int, ArrayLike]: ... | |
def read(self, rows: int | None = ...) -> dict[int, ArrayLike]: ... |
pandas/_libs/parsers.pyi
Outdated
comment=..., | ||
decimal: bytes | str = ..., # single-character only | ||
thousands: bytes | str | None = ..., # single-character only | ||
dtype: Dtype | dict[Any, Dtype] = ..., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want to avoid using Any, maybe could use Hashable. (which is effectively Any for a dictionary key)
this fails with error: Dict entry 0 has incompatible type "List[<nothing>]": "int"; expected "Hashable": "int" [dict-item]
from __future__ import annotations
from typing import Hashable
def func(a: dict[Hashable, int]):
pass
func({list(): 3})
but this passes mypy checks
from __future__ import annotations
from typing import Any
def func(a: dict[Any, int]):
pass
func({list(): 3})
although granted you can't create a dict with an unhashable key
Traceback (most recent call last):
File "/home/simon/t.py", line 9, in <module>
func({list(): 3})
TypeError: unhashable type: 'list'
min_periods, | ||
center, | ||
closed, | ||
self.index_array, # type: ignore[arg-type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mroeschke can we rule out getting here with self.index_array being None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For VariableWindowIndexer
, yes index_array
should not be None
can you merge master |
rebased + green |
num_values, | ||
self.window_size, | ||
min_periods, | ||
center, # type: ignore[arg-type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so center could be None according to the docstring, but once passed on to cython would be interpreted as False?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my impression is that the annotation here is wrong, which im putting an ignore on for now
@@ -15,7 +15,7 @@ def calculate_variable_window_bounds( | |||
int64_t window_size, | |||
object min_periods, # unused but here to match get_window_bounds signature | |||
bint center, | |||
object closed, | |||
str closed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be None? does cython include implicit Optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe update docstring. since we have
# default is 'right'
if closed is None:
closed = 'right'
in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does cython include implicit Optional?
for cdef functions, implicit Optional is always in effect