Skip to content

Commit 38aef17

Browse files
simonjayhawkinsjbrockmendel
authored andcommitted
CI: unpin numpy for CI / Checks github action (pandas-dev#36092)
1 parent d95650d commit 38aef17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+2444
-590
lines changed

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ channels:
33
- conda-forge
44
dependencies:
55
# required
6-
- numpy>=1.16.5, <1.20 # gh-39513
6+
- numpy>=1.16.5
77
- python=3
88
- python-dateutil>=2.7.3
99
- pytz

pandas/compat/numpy/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def np_datetime64_compat(s, *args, **kwargs):
4343
warning, when need to pass '2015-01-01 09:00:00'
4444
"""
4545
s = tz_replacer(s)
46-
return np.datetime64(s, *args, **kwargs)
46+
# error: No overload variant of "datetime64" matches argument types "Any",
47+
# "Tuple[Any, ...]", "Dict[str, Any]"
48+
return np.datetime64(s, *args, **kwargs) # type: ignore[call-overload]
4749

4850

4951
def np_array_datetime64_compat(arr, *args, **kwargs):

pandas/core/aggregation.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ def normalize_keyword_aggregation(kwargs: dict) -> Tuple[dict, List[str], List[i
181181

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

186188

187189
def _make_unique_kwarg_list(

pandas/core/algorithms.py

+119-27
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
157157
with catch_warnings():
158158
simplefilter("ignore", np.ComplexWarning)
159159
values = ensure_float64(values)
160-
return values, np.dtype("float64")
160+
# error: Incompatible return value type (got "Tuple[ExtensionArray,
161+
# dtype[floating[_64Bit]]]", expected "Tuple[ndarray, Union[dtype[Any],
162+
# ExtensionDtype]]")
163+
return values, np.dtype("float64") # type: ignore[return-value]
161164

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

176-
values = TimedeltaIndex(values)._data
179+
# error: Incompatible types in assignment (expression has type
180+
# "TimedeltaArray", variable has type "ndarray")
181+
values = TimedeltaIndex(values)._data # type: ignore[assignment]
177182
else:
178183
# Datetime
179184
if values.ndim > 1 and is_datetime64_ns_dtype(values.dtype):
@@ -182,27 +187,45 @@ def _ensure_data(values: ArrayLike) -> Tuple[np.ndarray, DtypeObj]:
182187
# TODO(EA2D): special case not needed with 2D EAs
183188
asi8 = values.view("i8")
184189
dtype = values.dtype
185-
return asi8, dtype
190+
# error: Incompatible return value type (got "Tuple[Any,
191+
# Union[dtype, ExtensionDtype, None]]", expected
192+
# "Tuple[ndarray, Union[dtype, ExtensionDtype]]")
193+
return asi8, dtype # type: ignore[return-value]
186194

187195
from pandas import DatetimeIndex
188196

189-
values = DatetimeIndex(values)._data
197+
# Incompatible types in assignment (expression has type "DatetimeArray",
198+
# variable has type "ndarray")
199+
values = DatetimeIndex(values)._data # type: ignore[assignment]
190200
dtype = values.dtype
191-
return values.asi8, dtype
201+
# error: Item "ndarray" of "Union[PeriodArray, Any, ndarray]" has no attribute
202+
# "asi8"
203+
return values.asi8, dtype # type: ignore[union-attr]
192204

193205
elif is_categorical_dtype(values.dtype):
194-
values = cast("Categorical", values)
195-
values = values.codes
206+
# error: Incompatible types in assignment (expression has type "Categorical",
207+
# variable has type "ndarray")
208+
values = cast("Categorical", values) # type: ignore[assignment]
209+
# error: Incompatible types in assignment (expression has type "ndarray",
210+
# variable has type "ExtensionArray")
211+
# error: Item "ndarray" of "Union[Any, ndarray]" has no attribute "codes"
212+
values = values.codes # type: ignore[assignment,union-attr]
196213
dtype = pandas_dtype("category")
197214

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

202-
return values, dtype
219+
# error: Incompatible return value type (got "Tuple[ExtensionArray,
220+
# Union[dtype[Any], ExtensionDtype]]", expected "Tuple[ndarray,
221+
# Union[dtype[Any], ExtensionDtype]]")
222+
return values, dtype # type: ignore[return-value]
203223

204224
# we have failed, return object
205-
values = np.asarray(values, dtype=object)
225+
226+
# error: Incompatible types in assignment (expression has type "ndarray", variable
227+
# has type "ExtensionArray")
228+
values = np.asarray(values, dtype=object) # type: ignore[assignment]
206229
return ensure_object(values), np.dtype("object")
207230

208231

@@ -227,24 +250,40 @@ def _reconstruct_data(
227250
return values
228251

229252
if is_extension_array_dtype(dtype):
230-
cls = dtype.construct_array_type()
253+
# error: Item "dtype[Any]" of "Union[dtype[Any], ExtensionDtype]" has no
254+
# attribute "construct_array_type"
255+
cls = dtype.construct_array_type() # type: ignore[union-attr]
231256
if isinstance(values, cls) and values.dtype == dtype:
232257
return values
233258

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

238268
# we only support object dtypes bool Index
239269
if isinstance(original, ABCIndex):
240270
values = values.astype(object, copy=False)
241271
elif dtype is not None:
242272
if is_datetime64_dtype(dtype):
243-
dtype = "datetime64[ns]"
273+
# error: Incompatible types in assignment (expression has type
274+
# "str", variable has type "Union[dtype, ExtensionDtype]")
275+
dtype = "datetime64[ns]" # type: ignore[assignment]
244276
elif is_timedelta64_dtype(dtype):
245-
dtype = "timedelta64[ns]"
277+
# error: Incompatible types in assignment (expression has type
278+
# "str", variable has type "Union[dtype, ExtensionDtype]")
279+
dtype = "timedelta64[ns]" # type: ignore[assignment]
246280

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

249288
return values
250289

@@ -296,14 +335,18 @@ def _get_values_for_rank(values: ArrayLike):
296335
if is_categorical_dtype(values):
297336
values = cast("Categorical", values)._values_for_rank()
298337

299-
values, _ = _ensure_data(values)
338+
# error: Incompatible types in assignment (expression has type "ndarray", variable
339+
# has type "ExtensionArray")
340+
values, _ = _ensure_data(values) # type: ignore[assignment]
300341
return values
301342

302343

303344
def get_data_algo(values: ArrayLike):
304345
values = _get_values_for_rank(values)
305346

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

309352
return htable, values
@@ -460,17 +503,46 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> np.ndarray:
460503
)
461504

462505
if not isinstance(values, (ABCIndex, ABCSeries, ABCExtensionArray, np.ndarray)):
463-
values = _ensure_arraylike(list(values))
506+
# error: Incompatible types in assignment (expression has type "ExtensionArray",
507+
# variable has type "Index")
508+
# error: Incompatible types in assignment (expression has type "ExtensionArray",
509+
# variable has type "Series")
510+
# error: Incompatible types in assignment (expression has type "ExtensionArray",
511+
# variable has type "ndarray")
512+
values = _ensure_arraylike(list(values)) # type: ignore[assignment]
464513
elif isinstance(values, ABCMultiIndex):
465514
# Avoid raising in extract_array
466-
values = np.array(values)
467-
else:
468-
values = extract_array(values, extract_numpy=True)
469515

470-
comps = _ensure_arraylike(comps)
471-
comps = extract_array(comps, extract_numpy=True)
516+
# error: Incompatible types in assignment (expression has type "ndarray",
517+
# variable has type "ExtensionArray")
518+
# error: Incompatible types in assignment (expression has type "ndarray",
519+
# variable has type "Index")
520+
# error: Incompatible types in assignment (expression has type "ndarray",
521+
# variable has type "Series")
522+
values = np.array(values) # type: ignore[assignment]
523+
else:
524+
# error: Incompatible types in assignment (expression has type "Union[Any,
525+
# ExtensionArray]", variable has type "Index")
526+
# error: Incompatible types in assignment (expression has type "Union[Any,
527+
# ExtensionArray]", variable has type "Series")
528+
values = extract_array(values, extract_numpy=True) # type: ignore[assignment]
529+
530+
# error: Incompatible types in assignment (expression has type "ExtensionArray",
531+
# variable has type "Index")
532+
# error: Incompatible types in assignment (expression has type "ExtensionArray",
533+
# variable has type "Series")
534+
# error: Incompatible types in assignment (expression has type "ExtensionArray",
535+
# variable has type "ndarray")
536+
comps = _ensure_arraylike(comps) # type: ignore[assignment]
537+
# error: Incompatible types in assignment (expression has type "Union[Any,
538+
# ExtensionArray]", variable has type "Index")
539+
# error: Incompatible types in assignment (expression has type "Union[Any,
540+
# ExtensionArray]", variable has type "Series")
541+
comps = extract_array(comps, extract_numpy=True) # type: ignore[assignment]
472542
if is_extension_array_dtype(comps.dtype):
473-
return comps.isin(values)
543+
# error: Incompatible return value type (got "Series", expected "ndarray")
544+
# error: Item "ndarray" of "Union[Any, ndarray]" has no attribute "isin"
545+
return comps.isin(values) # type: ignore[return-value,union-attr]
474546

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

503575
else:
504-
common = np.find_common_type([values.dtype, comps.dtype], [])
576+
# error: List item 0 has incompatible type "Union[Any, dtype[Any],
577+
# ExtensionDtype]"; expected "Union[dtype[Any], None, type, _SupportsDType, str,
578+
# Tuple[Any, Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any,
579+
# Any]]"
580+
# error: List item 1 has incompatible type "Union[Any, ExtensionDtype]";
581+
# expected "Union[dtype[Any], None, type, _SupportsDType, str, Tuple[Any,
582+
# Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]"
583+
# error: List item 1 has incompatible type "Union[dtype[Any], ExtensionDtype]";
584+
# expected "Union[dtype[Any], None, type, _SupportsDType, str, Tuple[Any,
585+
# Union[int, Sequence[int]]], List[Any], _DTypeDict, Tuple[Any, Any]]"
586+
common = np.find_common_type(
587+
[values.dtype, comps.dtype], [] # type: ignore[list-item]
588+
)
505589
values = values.astype(common, copy=False)
506590
comps = comps.astype(common, copy=False)
507591
name = common.name
@@ -916,7 +1000,9 @@ def duplicated(values: ArrayLike, keep: Union[str, bool] = "first") -> np.ndarra
9161000
-------
9171001
duplicated : ndarray
9181002
"""
919-
values, _ = _ensure_data(values)
1003+
# error: Incompatible types in assignment (expression has type "ndarray", variable
1004+
# has type "ExtensionArray")
1005+
values, _ = _ensure_data(values) # type: ignore[assignment]
9201006
ndtype = values.dtype.name
9211007
f = getattr(htable, f"duplicated_{ndtype}")
9221008
return f(values, keep=keep)
@@ -1188,7 +1274,9 @@ def _get_score(at):
11881274
else:
11891275
q = np.asarray(q, np.float64)
11901276
result = [_get_score(x) for x in q]
1191-
result = np.array(result, dtype=np.float64)
1277+
# error: Incompatible types in assignment (expression has type
1278+
# "ndarray", variable has type "List[Any]")
1279+
result = np.array(result, dtype=np.float64) # type: ignore[assignment]
11921280
return result
11931281

11941282

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

17811873
sorter = None
17821874

pandas/core/apply.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,11 @@ def apply_standard(self) -> FrameOrSeriesUnion:
10161016

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

10211025
# row-wise access
10221026
if is_extension_array_dtype(obj.dtype) and hasattr(obj._values, "map"):

pandas/core/array_algos/putmask.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ def putmask_smart(values: np.ndarray, mask: np.ndarray, new) -> np.ndarray:
120120
return _putmask_preserve(values, new, mask)
121121

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

125129
return _putmask_preserve(values, new, mask)
126130

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

192-
mask = np.asarray(mask, dtype=bool)
193-
return mask
195+
# error: Incompatible types in assignment (expression has type "ndarray",
196+
# variable has type "ExtensionArray")
197+
mask = mask.to_numpy(dtype=bool, na_value=False) # type: ignore[assignment]
198+
199+
# error: Incompatible types in assignment (expression has type "ndarray", variable
200+
# has type "ExtensionArray")
201+
mask = np.asarray(mask, dtype=bool) # type: ignore[assignment]
202+
# error: Incompatible return value type (got "ExtensionArray", expected "ndarray")
203+
return mask # type: ignore[return-value]
194204

195205

196206
def setitem_datetimelike_compat(values: np.ndarray, num_set: int, other):

pandas/core/array_algos/quantile.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,17 @@ def quantile_ea_compat(
143143
mask = np.asarray(values.isna())
144144
mask = np.atleast_2d(mask)
145145

146-
values, fill_value = values._values_for_factorize()
147-
values = np.atleast_2d(values)
148-
149-
result = quantile_with_mask(values, mask, fill_value, qs, interpolation, axis)
146+
# error: Incompatible types in assignment (expression has type "ndarray", variable
147+
# has type "ExtensionArray")
148+
values, fill_value = values._values_for_factorize() # type: ignore[assignment]
149+
# error: No overload variant of "atleast_2d" matches argument type "ExtensionArray"
150+
values = np.atleast_2d(values) # type: ignore[call-overload]
151+
152+
# error: Argument 1 to "quantile_with_mask" has incompatible type "ExtensionArray";
153+
# expected "ndarray"
154+
result = quantile_with_mask(
155+
values, mask, fill_value, qs, interpolation, axis # type: ignore[arg-type]
156+
)
150157

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

163-
return result
170+
# error: Incompatible return value type (got "ndarray", expected "ExtensionArray")
171+
return result # type: ignore[return-value]

pandas/core/array_algos/replace.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ def _check_comparison_types(
9595

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

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

154156
if mask is None:
155-
values[:] = f(values)
157+
# error: Invalid index type "slice" for "ExtensionArray"; expected type
158+
# "Union[int, ndarray]"
159+
values[:] = f(values) # type: ignore[index]
156160
else:
157161
values[mask] = f(values[mask])

0 commit comments

Comments
 (0)