-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: fix ignores #40389
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: fix ignores #40389
Changes from all commits
8700ee0
efc82cf
4cca1bb
38fc503
6cfc1ea
8ec8838
f03029b
926936b
f559025
b67a90f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ class providing the base-class of operations. | |
) | ||
import pandas._libs.groupby as libgroupby | ||
from pandas._typing import ( | ||
ArrayLike, | ||
F, | ||
FrameOrSeries, | ||
FrameOrSeriesUnion, | ||
|
@@ -68,7 +69,6 @@ class providing the base-class of operations. | |
ensure_float, | ||
is_bool_dtype, | ||
is_datetime64_dtype, | ||
is_extension_array_dtype, | ||
is_integer_dtype, | ||
is_numeric_dtype, | ||
is_object_dtype, | ||
|
@@ -85,6 +85,7 @@ class providing the base-class of operations. | |
from pandas.core.arrays import ( | ||
Categorical, | ||
DatetimeArray, | ||
ExtensionArray, | ||
) | ||
from pandas.core.base import ( | ||
DataError, | ||
|
@@ -2265,37 +2266,31 @@ def quantile(self, q=0.5, interpolation: str = "linear"): | |
""" | ||
from pandas import concat | ||
|
||
def pre_processor(vals: np.ndarray) -> Tuple[np.ndarray, Optional[Type]]: | ||
def pre_processor(vals: ArrayLike) -> Tuple[np.ndarray, Optional[np.dtype]]: | ||
if is_object_dtype(vals): | ||
raise TypeError( | ||
"'quantile' cannot be performed against 'object' dtypes!" | ||
) | ||
|
||
inference = None | ||
inference: Optional[np.dtype] = None | ||
if is_integer_dtype(vals.dtype): | ||
if is_extension_array_dtype(vals.dtype): | ||
# error: "ndarray" has no attribute "to_numpy" | ||
vals = vals.to_numpy( # type: ignore[attr-defined] | ||
dtype=float, na_value=np.nan | ||
) | ||
inference = np.int64 | ||
elif is_bool_dtype(vals.dtype) and is_extension_array_dtype(vals.dtype): | ||
# error: "ndarray" has no attribute "to_numpy" | ||
vals = vals.to_numpy( # type: ignore[attr-defined] | ||
dtype=float, na_value=np.nan | ||
) | ||
if isinstance(vals, ExtensionArray): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the function signature has vals: np.ndarray. also needs updating |
||
out = vals.to_numpy(dtype=float, na_value=np.nan) | ||
else: | ||
out = vals | ||
inference = np.dtype(np.int64) | ||
elif is_bool_dtype(vals.dtype) and isinstance(vals, ExtensionArray): | ||
out = vals.to_numpy(dtype=float, na_value=np.nan) | ||
elif is_datetime64_dtype(vals.dtype): | ||
# error: Incompatible types in assignment (expression has type | ||
# "str", variable has type "Optional[Type[int64]]") | ||
inference = "datetime64[ns]" # type: ignore[assignment] | ||
vals = np.asarray(vals).astype(float) | ||
inference = np.dtype("datetime64[ns]") | ||
out = np.asarray(vals).astype(float) | ||
elif is_timedelta64_dtype(vals.dtype): | ||
# error: Incompatible types in assignment (expression has type "str", | ||
# variable has type "Optional[Type[signedinteger[Any]]]") | ||
inference = "timedelta64[ns]" # type: ignore[assignment] | ||
vals = np.asarray(vals).astype(float) | ||
inference = np.dtype("timedelta64[ns]") | ||
out = np.asarray(vals).astype(float) | ||
else: | ||
out = np.asarray(vals) | ||
|
||
return vals, inference | ||
return out, inference | ||
|
||
def post_processor(vals: np.ndarray, inference: Optional[Type]) -> np.ndarray: | ||
if inference: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ | |
|
||
import itertools | ||
from typing import ( | ||
TYPE_CHECKING, | ||
List, | ||
Optional, | ||
Union, | ||
cast, | ||
) | ||
|
||
import numpy as np | ||
|
@@ -44,6 +46,9 @@ | |
get_group_index_sorter, | ||
) | ||
|
||
if TYPE_CHECKING: | ||
from pandas.core.arrays import ExtensionArray | ||
|
||
|
||
class _Unstacker: | ||
""" | ||
|
@@ -942,11 +947,11 @@ def _get_dummies_1d( | |
data, | ||
prefix, | ||
prefix_sep="_", | ||
dummy_na=False, | ||
sparse=False, | ||
drop_first=False, | ||
dummy_na: bool = False, | ||
sparse: bool = False, | ||
drop_first: bool = False, | ||
dtype: Optional[Dtype] = None, | ||
): | ||
) -> DataFrame: | ||
from pandas.core.reshape.concat import concat | ||
|
||
# Series avoids inconsistent NaN handling | ||
|
@@ -1029,6 +1034,8 @@ def get_empty_frame(data) -> DataFrame: | |
sparse_series.append(Series(data=sarr, index=index, name=col)) | ||
|
||
out = concat(sparse_series, axis=1, copy=False) | ||
# TODO: overload concat with Literal for axis | ||
out = cast(DataFrame, out) | ||
return out | ||
|
||
else: | ||
|
@@ -1045,7 +1052,9 @@ def get_empty_frame(data) -> DataFrame: | |
return DataFrame(dummy_mat, index=index, columns=dummy_cols) | ||
|
||
|
||
def _reorder_for_extension_array_stack(arr, n_rows: int, n_columns: int): | ||
def _reorder_for_extension_array_stack( | ||
arr: ExtensionArray, n_rows: int, n_columns: int | ||
) -> ExtensionArray: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably should be a typevar. but also ok to leave as is for now if not needed as this is internal |
||
""" | ||
Re-orders the values when stacking multiple extension-arrays. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,6 @@ | |
_INT64_MAX = np.iinfo(np.int64).max | ||
|
||
|
||
# error: Function "numpy.array" is not valid as a type | ||
def get_indexer_indexer( | ||
target: Index, | ||
level: Union[str, int, List[str], List[int]], | ||
|
@@ -52,7 +51,7 @@ def get_indexer_indexer( | |
na_position: str, | ||
sort_remaining: bool, | ||
key: IndexKeyFunc, | ||
) -> Optional[np.array]: # type: ignore[valid-type] | ||
) -> Optional[np.ndarray]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you found the bonus low hanger! 😄 |
||
""" | ||
Helper method that return the indexer according to input parameters for | ||
the sort_index method of DataFrame and Series. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,7 @@ def _convert_listlike(arg, unit=None, errors="raise", name=None): | |
arg = np.array(list(arg), dtype=object) | ||
|
||
try: | ||
value = sequence_to_td64ns(arg, unit=unit, errors=errors, copy=False)[0] | ||
td64arr = sequence_to_td64ns(arg, unit=unit, errors=errors, copy=False)[0] | ||
except ValueError: | ||
if errors == "ignore": | ||
return arg | ||
|
@@ -181,7 +181,5 @@ def _convert_listlike(arg, unit=None, errors="raise", name=None): | |
|
||
from pandas import TimedeltaIndex | ||
|
||
# error: Incompatible types in assignment (expression has type "TimedeltaIndex", | ||
# variable has type "ndarray") | ||
value = TimedeltaIndex(value, unit="ns", name=name) # type: ignore[assignment] | ||
value = TimedeltaIndex(td64arr, unit="ns", name=name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could also |
||
return value |
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.
the return type is
Tuple[np.ndarray, Optional[Type]]
in the function signature. so that can also now be narrowed.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.
was needed anyway for mypy fixup