Skip to content

Commit

Permalink
CI: unpin numpy for CI / Checks github action (pandas-dev#36092)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjayhawkins authored and jbrockmendel committed Mar 11, 2021
1 parent d95650d commit 38aef17
Show file tree
Hide file tree
Showing 91 changed files with 2,444 additions and 590 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
dependencies:
# required
- numpy>=1.16.5, <1.20 # gh-39513
- numpy>=1.16.5
- python=3
- python-dateutil>=2.7.3
- pytz
Expand Down
4 changes: 3 additions & 1 deletion pandas/compat/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def np_datetime64_compat(s, *args, **kwargs):
warning, when need to pass '2015-01-01 09:00:00'
"""
s = tz_replacer(s)
return np.datetime64(s, *args, **kwargs)
# error: No overload variant of "datetime64" matches argument types "Any",
# "Tuple[Any, ...]", "Dict[str, Any]"
return np.datetime64(s, *args, **kwargs) # type: ignore[call-overload]


def np_array_datetime64_compat(arr, *args, **kwargs):
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def normalize_keyword_aggregation(kwargs: dict) -> Tuple[dict, List[str], List[i

# get the new index of columns by comparison
col_idx_order = Index(uniquified_aggspec).get_indexer(uniquified_order)
return aggspec, columns, col_idx_order
# error: Incompatible return value type (got "Tuple[defaultdict[Any, Any],
# Any, ndarray]", expected "Tuple[Dict[Any, Any], List[str], List[int]]")
return aggspec, columns, col_idx_order # type: ignore[return-value]


def _make_unique_kwarg_list(
Expand Down
146 changes: 119 additions & 27 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
with catch_warnings():
simplefilter("ignore", np.ComplexWarning)
values = ensure_float64(values)
return values, np.dtype("float64")
# error: Incompatible return value type (got "Tuple[ExtensionArray,
# dtype[floating[_64Bit]]]", expected "Tuple[ndarray, Union[dtype[Any],
# ExtensionDtype]]")
return values, np.dtype("float64") # type: ignore[return-value]

except (TypeError, ValueError, OverflowError):
# if we are trying to coerce to a dtype
Expand All @@ -173,7 +176,9 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
elif is_timedelta64_dtype(values.dtype):
from pandas import TimedeltaIndex

values = TimedeltaIndex(values)._data
# error: Incompatible types in assignment (expression has type
# "TimedeltaArray", variable has type "ndarray")
values = TimedeltaIndex(values)._data # type: ignore[assignment]
else:
# Datetime
if values.ndim > 1 and is_datetime64_ns_dtype(values.dtype):
Expand All @@ -182,27 +187,45 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
# TODO(EA2D): special case not needed with 2D EAs
asi8 = values.view("i8")
dtype = values.dtype
return asi8, dtype
# error: Incompatible return value type (got "Tuple[Any,
# Union[dtype, ExtensionDtype, None]]", expected
# "Tuple[ndarray, Union[dtype, ExtensionDtype]]")
return asi8, dtype # type: ignore[return-value]

from pandas import DatetimeIndex

values = DatetimeIndex(values)._data
# Incompatible types in assignment (expression has type "DatetimeArray",
# variable has type "ndarray")
values = DatetimeIndex(values)._data # type: ignore[assignment]
dtype = values.dtype
return values.asi8, dtype
# error: Item "ndarray" of "Union[PeriodArray, Any, ndarray]" has no attribute
# "asi8"
return values.asi8, dtype # type: ignore[union-attr]

elif is_categorical_dtype(values.dtype):
values = cast("Categorical", values)
values = values.codes
# error: Incompatible types in assignment (expression has type "Categorical",
# variable has type "ndarray")
values = cast("Categorical", values) # type: ignore[assignment]
# error: Incompatible types in assignment (expression has type "ndarray",
# variable has type "ExtensionArray")
# error: Item "ndarray" of "Union[Any, ndarray]" has no attribute "codes"
values = values.codes # type: ignore[assignment,union-attr]
dtype = pandas_dtype("category")

# we are actually coercing to int64
# until our algos support int* directly (not all do)
values = ensure_int64(values)

return values, dtype
# error: Incompatible return value type (got "Tuple[ExtensionArray,
# Union[dtype[Any], ExtensionDtype]]", expected "Tuple[ndarray,
# Union[dtype[Any], ExtensionDtype]]")
return values, dtype # type: ignore[return-value]

# we have failed, return object
values = np.asarray(values, dtype=object)

# error: Incompatible types in assignment (expression has type "ndarray", variable
# has type "ExtensionArray")
values = np.asarray(values, dtype=object) # type: ignore[assignment]
return ensure_object(values), np.dtype("object")


Expand All @@ -227,24 +250,40 @@ def _reconstruct_data(
return values

if is_extension_array_dtype(dtype):
cls = dtype.construct_array_type()
# error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no
# attribute "construct_array_type"
cls = dtype.construct_array_type() # type: ignore[union-attr]
if isinstance(values, cls) and values.dtype == dtype:
return values

values = cls._from_sequence(values)
elif is_bool_dtype(dtype):
values = values.astype(dtype, copy=False)
# error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has
# incompatible type "Union[dtype, ExtensionDtype]"; expected
# "Union[dtype, None, type, _SupportsDtype, str, Tuple[Any, int],
# Tuple[Any, Union[int, Sequence[int]]], List[Any], _DtypeDict,
# Tuple[Any, Any]]"
values = values.astype(dtype, copy=False) # type: ignore[arg-type]

# we only support object dtypes bool Index
if isinstance(original, ABCIndex):
values = values.astype(object, copy=False)
elif dtype is not None:
if is_datetime64_dtype(dtype):
dtype = "datetime64[ns]"
# error: Incompatible types in assignment (expression has type
# "str", variable has type "Union[dtype, ExtensionDtype]")
dtype = "datetime64[ns]" # type: ignore[assignment]
elif is_timedelta64_dtype(dtype):
dtype = "timedelta64[ns]"
# error: Incompatible types in assignment (expression has type
# "str", variable has type "Union[dtype, ExtensionDtype]")
dtype = "timedelta64[ns]" # type: ignore[assignment]

values = values.astype(dtype, copy=False)
# error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has
# incompatible type "Union[dtype, ExtensionDtype]"; expected
# "Union[dtype, None, type, _SupportsDtype, str, Tuple[Any, int],
# Tuple[Any, Union[int, Sequence[int]]], List[Any], _DtypeDict,
# Tuple[Any, Any]]"
values = values.astype(dtype, copy=False) # type: ignore[arg-type]

return values

Expand Down Expand Up @@ -296,14 +335,18 @@ def _get_values_for_rank(values: ArrayLike):
if is_categorical_dtype(values):
values = cast("Categorical", values)._values_for_rank()

values, _ = _ensure_data(values)
# error: Incompatible types in assignment (expression has type "ndarray", variable
# has type "ExtensionArray")
values, _ = _ensure_data(values) # type: ignore[assignment]
return values


def get_data_algo(values: ArrayLike):
values = _get_values_for_rank(values)

ndtype = _check_object_for_strings(values)
# error: Argument 1 to "_check_object_for_strings" has incompatible type
# "ExtensionArray"; expected "ndarray"
ndtype = _check_object_for_strings(values) # type: ignore[arg-type]
htable = _hashtables.get(ndtype, _hashtables["object"])

return htable, values
Expand Down Expand Up @@ -460,17 +503,46 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> np.ndarray:
)

if not isinstance(values, (ABCIndex, ABCSeries, ABCExtensionArray, np.ndarray)):
values = _ensure_arraylike(list(values))
# error: Incompatible types in assignment (expression has type "ExtensionArray",
# variable has type "Index")
# error: Incompatible types in assignment (expression has type "ExtensionArray",
# variable has type "Series")
# error: Incompatible types in assignment (expression has type "ExtensionArray",
# variable has type "ndarray")
values = _ensure_arraylike(list(values)) # type: ignore[assignment]
elif isinstance(values, ABCMultiIndex):
# Avoid raising in extract_array
values = np.array(values)
else:
values = extract_array(values, extract_numpy=True)

comps = _ensure_arraylike(comps)
comps = extract_array(comps, extract_numpy=True)
# error: Incompatible types in assignment (expression has type "ndarray",
# variable has type "ExtensionArray")
# error: Incompatible types in assignment (expression has type "ndarray",
# variable has type "Index")
# error: Incompatible types in assignment (expression has type "ndarray",
# variable has type "Series")
values = np.array(values) # type: ignore[assignment]
else:
# error: Incompatible types in assignment (expression has type "Union[Any,
# ExtensionArray]", variable has type "Index")
# error: Incompatible types in assignment (expression has type "Union[Any,
# ExtensionArray]", variable has type "Series")
values = extract_array(values, extract_numpy=True) # type: ignore[assignment]

# error: Incompatible types in assignment (expression has type "ExtensionArray",
# variable has type "Index")
# error: Incompatible types in assignment (expression has type "ExtensionArray",
# variable has type "Series")
# error: Incompatible types in assignment (expression has type "ExtensionArray",
# variable has type "ndarray")
comps = _ensure_arraylike(comps) # type: ignore[assignment]
# error: Incompatible types in assignment (expression has type "Union[Any,
# ExtensionArray]", variable has type "Index")
# error: Incompatible types in assignment (expression has type "Union[Any,
# ExtensionArray]", variable has type "Series")
comps = extract_array(comps, extract_numpy=True) # type: ignore[assignment]
if is_extension_array_dtype(comps.dtype):
return comps.isin(values)
# error: Incompatible return value type (got "Series", expected "ndarray")
# error: Item "ndarray" of "Union[Any, ndarray]" has no attribute "isin"
return comps.isin(values) # type: ignore[return-value,union-attr]

elif needs_i8_conversion(comps.dtype):
# Dispatch to DatetimeLikeArrayMixin.isin
Expand Down Expand Up @@ -501,7 +573,19 @@ def f(c, v):
f = np.in1d

else:
common = np.find_common_type([values.dtype, comps.dtype], [])
# error: List item 0 has incompatible type "Union[Any, dtype[Any],
# ExtensionDtype]"; expected "Union[dtype[Any], None, type, _SupportsDType, str,
# Tuple[Any, Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any,
# Any]]"
# error: List item 1 has incompatible type "Union[Any, ExtensionDtype]";
# expected "Union[dtype[Any], None, type, _SupportsDType, str, Tuple[Any,
# Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]"
# error: List item 1 has incompatible type "Union[dtype[Any], ExtensionDtype]";
# expected "Union[dtype[Any], None, type, _SupportsDType, str, Tuple[Any,
# Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]"
common = np.find_common_type(
[values.dtype, comps.dtype], [] # type: ignore[list-item]
)
values = values.astype(common, copy=False)
comps = comps.astype(common, copy=False)
name = common.name
Expand Down Expand Up @@ -916,7 +1000,9 @@ def duplicated(values: ArrayLike, keep: Union[str, bool] = "first") -> np.ndarra
-------
duplicated : ndarray
"""
values, _ = _ensure_data(values)
# error: Incompatible types in assignment (expression has type "ndarray", variable
# has type "ExtensionArray")
values, _ = _ensure_data(values) # type: ignore[assignment]
ndtype = values.dtype.name
f = getattr(htable, f"duplicated_{ndtype}")
return f(values, keep=keep)
Expand Down Expand Up @@ -1188,7 +1274,9 @@ def _get_score(at):
else:
q = np.asarray(q, np.float64)
result = [_get_score(x) for x in q]
result = np.array(result, dtype=np.float64)
# error: Incompatible types in assignment (expression has type
# "ndarray", variable has type "List[Any]")
result = np.array(result, dtype=np.float64) # type: ignore[assignment]
return result


Expand Down Expand Up @@ -1776,7 +1864,11 @@ def safe_sort(
if not isinstance(values, (np.ndarray, ABCExtensionArray)):
# don't convert to string types
dtype, _ = infer_dtype_from_array(values)
values = np.asarray(values, dtype=dtype)
# error: Argument "dtype" to "asarray" has incompatible type "Union[dtype[Any],
# ExtensionDtype]"; expected "Union[dtype[Any], None, type, _SupportsDType, str,
# Union[Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], List[Any],
# _DTypeDict, Tuple[Any, Any]]]"
values = np.asarray(values, dtype=dtype) # type: ignore[arg-type]

sorter = None

Expand Down
6 changes: 5 additions & 1 deletion pandas/core/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,11 @@ def apply_standard(self) -> FrameOrSeriesUnion:

with np.errstate(all="ignore"):
if isinstance(f, np.ufunc):
return f(obj)
# error: Argument 1 to "__call__" of "ufunc" has incompatible type
# "Series"; expected "Union[Union[int, float, complex, str, bytes,
# generic], Sequence[Union[int, float, complex, str, bytes, generic]],
# Sequence[Sequence[Any]], _SupportsArray]"
return f(obj) # type: ignore[arg-type]

# row-wise access
if is_extension_array_dtype(obj.dtype) and hasattr(obj._values, "map"):
Expand Down
18 changes: 14 additions & 4 deletions pandas/core/array_algos/putmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def putmask_smart(values: np.ndarray, mask: np.ndarray, new) -> np.ndarray:
return _putmask_preserve(values, new, mask)

dtype = find_common_type([values.dtype, new.dtype])
values = values.astype(dtype)
# error: Argument 1 to "astype" of "_ArrayOrScalarCommon" has incompatible type
# "Union[dtype[Any], ExtensionDtype]"; expected "Union[dtype[Any], None, type,
# _SupportsDType, str, Union[Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]],
# List[Any], _DTypeDict, Tuple[Any, Any]]]"
values = values.astype(dtype) # type: ignore[arg-type]

return _putmask_preserve(values, new, mask)

Expand Down Expand Up @@ -187,10 +191,16 @@ def extract_bool_array(mask: ArrayLike) -> np.ndarray:
# We could have BooleanArray, Sparse[bool], ...
# Except for BooleanArray, this is equivalent to just
# np.asarray(mask, dtype=bool)
mask = mask.to_numpy(dtype=bool, na_value=False)

mask = np.asarray(mask, dtype=bool)
return mask
# error: Incompatible types in assignment (expression has type "ndarray",
# variable has type "ExtensionArray")
mask = mask.to_numpy(dtype=bool, na_value=False) # type: ignore[assignment]

# error: Incompatible types in assignment (expression has type "ndarray", variable
# has type "ExtensionArray")
mask = np.asarray(mask, dtype=bool) # type: ignore[assignment]
# error: Incompatible return value type (got "ExtensionArray", expected "ndarray")
return mask # type: ignore[return-value]


def setitem_datetimelike_compat(values: np.ndarray, num_set: int, other):
Expand Down
18 changes: 13 additions & 5 deletions pandas/core/array_algos/quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,17 @@ def quantile_ea_compat(
mask = np.asarray(values.isna())
mask = np.atleast_2d(mask)

values, fill_value = values._values_for_factorize()
values = np.atleast_2d(values)

result = quantile_with_mask(values, mask, fill_value, qs, interpolation, axis)
# error: Incompatible types in assignment (expression has type "ndarray", variable
# has type "ExtensionArray")
values, fill_value = values._values_for_factorize() # type: ignore[assignment]
# error: No overload variant of "atleast_2d" matches argument type "ExtensionArray"
values = np.atleast_2d(values) # type: ignore[call-overload]

# error: Argument 1 to "quantile_with_mask" has incompatible type "ExtensionArray";
# expected "ndarray"
result = quantile_with_mask(
values, mask, fill_value, qs, interpolation, axis # type: ignore[arg-type]
)

if not is_sparse(orig.dtype):
# shape[0] should be 1 as long as EAs are 1D
Expand All @@ -160,4 +167,5 @@ def quantile_ea_compat(
assert result.shape == (1, len(qs)), result.shape
result = type(orig)._from_factorized(result[0], orig)

return result
# error: Incompatible return value type (got "ndarray", expected "ExtensionArray")
return result # type: ignore[return-value]
8 changes: 6 additions & 2 deletions pandas/core/array_algos/replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def _check_comparison_types(

if is_numeric_v_string_like(a, b):
# GH#29553 avoid deprecation warnings from numpy
return np.zeros(a.shape, dtype=bool)
# error: Incompatible return value type (got "ndarray", expected
# "Union[ExtensionArray, bool]")
return np.zeros(a.shape, dtype=bool) # type: ignore[return-value]

elif is_datetimelike_v_numeric(a, b):
# GH#29553 avoid deprecation warnings from numpy
Expand Down Expand Up @@ -152,6 +154,8 @@ def re_replacer(s):
f = np.vectorize(re_replacer, otypes=[values.dtype])

if mask is None:
values[:] = f(values)
# error: Invalid index type "slice" for "ExtensionArray"; expected type
# "Union[int, ndarray]"
values[:] = f(values) # type: ignore[index]
else:
values[mask] = f(values[mask])
Loading

0 comments on commit 38aef17

Please sign in to comment.