Skip to content

Commit 1d2a9cb

Browse files
Backport PR #45212: CLN: suppress warnings (#45269)
Co-authored-by: jbrockmendel <[email protected]>
1 parent 13ec509 commit 1d2a9cb

File tree

13 files changed

+43
-22
lines changed

13 files changed

+43
-22
lines changed

doc/source/whatsnew/v1.4.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ Indexing
816816

817817
Missing
818818
^^^^^^^
819-
- Bug in :meth:`DataFrame.fillna` with limit and no method ignores axis='columns' or ``axis = 1`` (:issue:`40989`)
819+
- Bug in :meth:`DataFrame.fillna` with limit and no method ignores axis='columns' or ``axis = 1`` (:issue:`40989`, :issue:`17399`)
820820
- Bug in :meth:`DataFrame.fillna` not replacing missing values when using a dict-like ``value`` and duplicate column names (:issue:`43476`)
821821
- Bug in constructing a :class:`DataFrame` with a dictionary ``np.datetime64`` as a value and ``dtype='timedelta64[ns]'``, or vice-versa, incorrectly casting instead of raising (:issue:`44428`)
822822
- Bug in :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` with ``inplace=True`` not writing to the underlying array(s) in-place (:issue:`44749`)

pandas/_libs/lib.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ cpdef ndarray[object] ensure_string_array(
714714
return out
715715

716716
arr = arr.to_numpy()
717-
elif not isinstance(arr, np.ndarray):
717+
elif not util.is_array(arr):
718718
arr = np.array(arr, dtype="object")
719719

720720
result = np.asarray(arr, dtype="object")
@@ -729,7 +729,7 @@ cpdef ndarray[object] ensure_string_array(
729729
continue
730730

731731
if not checknull(val):
732-
if not isinstance(val, np.floating):
732+
if not util.is_float_object(val):
733733
# f"{val}" is faster than str(val)
734734
result[i] = f"{val}"
735735
else:

pandas/core/arrays/masked.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ def _quantile(
767767
We assume that all impacted cases are 1D-only.
768768
"""
769769
mask = np.atleast_2d(np.asarray(self.isna()))
770-
npvalues = np.atleast_2d(np.asarray(self))
770+
npvalues: np.ndarray = np.atleast_2d(np.asarray(self))
771771

772772
res = quantile_with_mask(
773773
npvalues,

pandas/core/dtypes/cast.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def ensure_dtype_can_hold_na(dtype: DtypeObj) -> DtypeObj:
459459
# TODO: ExtensionDtype.can_hold_na?
460460
return dtype
461461
elif dtype.kind == "b":
462-
return np.dtype(object)
462+
return _dtype_obj
463463
elif dtype.kind in ["i", "u"]:
464464
return np.dtype(np.float64)
465465
return dtype
@@ -522,7 +522,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
522522
# with object dtype there is nothing to promote, and the user can
523523
# pass pretty much any weird fill_value they like
524524
raise ValueError("fill_value must be a scalar")
525-
dtype = np.dtype(object)
525+
dtype = _dtype_obj
526526
return dtype, fill_value
527527

528528
kinds = ["i", "u", "f", "c", "m", "M"]
@@ -532,7 +532,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
532532
return dtype, fv
533533

534534
elif isna(fill_value):
535-
dtype = np.dtype(object)
535+
dtype = _dtype_obj
536536
if fill_value is None:
537537
# but we retain e.g. pd.NA
538538
fill_value = np.nan
@@ -551,7 +551,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan):
551551
# fv = dta._validate_setitem_value(fill_value)
552552
# return dta.dtype, fv
553553
# except (ValueError, TypeError):
554-
# return np.dtype(object), fill_value
554+
# return _dtype_obj, fill_value
555555
if isinstance(fill_value, date) and not isinstance(fill_value, datetime):
556556
# deprecate casting of date object to match infer_dtype_from_scalar
557557
# and DatetimeArray._validate_setitem_value
@@ -699,7 +699,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
699699
If False, scalar belongs to pandas extension types is inferred as
700700
object
701701
"""
702-
dtype: DtypeObj = np.dtype(object)
702+
dtype: DtypeObj = _dtype_obj
703703

704704
# a 1-element ndarray
705705
if isinstance(val, np.ndarray):
@@ -718,13 +718,13 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
718718
# instead of np.empty (but then you still don't want things
719719
# coming out as np.str_!
720720

721-
dtype = np.dtype(object)
721+
dtype = _dtype_obj
722722

723723
elif isinstance(val, (np.datetime64, datetime)):
724724
try:
725725
val = Timestamp(val)
726726
except OutOfBoundsDatetime:
727-
return np.dtype(object), val
727+
return _dtype_obj, val
728728

729729
# error: Non-overlapping identity check (left operand type: "Timestamp",
730730
# right operand type: "NaTType")
@@ -736,13 +736,13 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj,
736736
dtype = DatetimeTZDtype(unit="ns", tz=val.tz)
737737
else:
738738
# return datetimetz as object
739-
return np.dtype(object), val
739+
return _dtype_obj, val
740740

741741
elif isinstance(val, (np.timedelta64, timedelta)):
742742
try:
743743
val = Timedelta(val)
744744
except (OutOfBoundsTimedelta, OverflowError):
745-
dtype = np.dtype(object)
745+
dtype = _dtype_obj
746746
else:
747747
dtype = np.dtype("m8[ns]")
748748
val = np.timedelta64(val.value, "ns")
@@ -1911,7 +1911,7 @@ def construct_1d_arraylike_from_scalar(
19111911
try:
19121912
dtype, value = infer_dtype_from_scalar(value, pandas_dtype=True)
19131913
except OutOfBoundsDatetime:
1914-
dtype = np.dtype(object)
1914+
dtype = _dtype_obj
19151915

19161916
if isinstance(dtype, ExtensionDtype):
19171917
cls = dtype.construct_array_type()

pandas/core/indexing.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import (
55
TYPE_CHECKING,
66
Hashable,
7+
Sequence,
78
)
89
import warnings
910

@@ -2016,6 +2017,7 @@ def _ensure_iterable_column_indexer(self, column_indexer):
20162017
"""
20172018
Ensure that our column indexer is something that can be iterated over.
20182019
"""
2020+
ilocs: Sequence[int]
20192021
if is_integer(column_indexer):
20202022
ilocs = [column_indexer]
20212023
elif isinstance(column_indexer, slice):

pandas/core/internals/array_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ def make_empty(self, axes=None) -> SingleArrayManager:
12031203
"""Return an empty ArrayManager with index/array of length 0"""
12041204
if axes is None:
12051205
axes = [Index([], dtype=object)]
1206-
array = np.array([], dtype=self.dtype)
1206+
array: np.ndarray = np.array([], dtype=self.dtype)
12071207
return type(self)([array], axes)
12081208

12091209
@classmethod

pandas/core/internals/managers.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1090,14 +1090,12 @@ def iset(
10901090
# containing (self._blknos[loc], BlockPlacement(slice(0, 1, 1)))
10911091

10921092
# Check if we can use _iset_single fastpath
1093+
loc = cast(int, loc)
10931094
blkno = self.blknos[loc]
10941095
blk = self.blocks[blkno]
10951096
if len(blk._mgr_locs) == 1: # TODO: fastest way to check this?
10961097
return self._iset_single(
1097-
# error: Argument 1 to "_iset_single" of "BlockManager" has
1098-
# incompatible type "Union[int, slice, ndarray[Any, Any]]";
1099-
# expected "int"
1100-
loc, # type:ignore[arg-type]
1098+
loc,
11011099
value,
11021100
inplace=inplace,
11031101
blkno=blkno,

pandas/core/reshape/reshape.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ def get_empty_frame(data) -> DataFrame:
10211021
if isinstance(data, Series):
10221022
index = data.index
10231023
else:
1024-
index = np.arange(len(data))
1024+
index = Index(range(len(data)))
10251025
return DataFrame(index=index)
10261026

10271027
# if all NaN
@@ -1031,7 +1031,7 @@ def get_empty_frame(data) -> DataFrame:
10311031
codes = codes.copy()
10321032
if dummy_na:
10331033
codes[codes == -1] = len(levels)
1034-
levels = np.append(levels, np.nan)
1034+
levels = levels.insert(len(levels), np.nan)
10351035

10361036
# if dummy_na, we just fake a nan level. drop_first will drop it again
10371037
if drop_first and len(levels) == 1:

pandas/tests/frame/test_ufunc.py

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@ def test_alignment_deprecation_many_inputs(request):
269269
)
270270
request.node.add_marker(mark)
271271

272+
mark = pytest.mark.filterwarnings(
273+
"ignore:`np.MachAr` is deprecated.*:DeprecationWarning"
274+
)
275+
request.node.add_marker(mark)
276+
272277
@vectorize([float64(float64, float64, float64)])
273278
def my_ufunc(x, y, z):
274279
return x + y + z

pandas/tests/io/test_parquet.py

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
with catch_warnings():
4444
# `np.bool` is a deprecated alias...
4545
filterwarnings("ignore", "`np.bool`", category=DeprecationWarning)
46+
# accessing pd.Int64Index in pd namespace
47+
filterwarnings("ignore", ".*Int64Index.*", category=FutureWarning)
48+
4649
import fastparquet
4750

4851
_HAVE_FASTPARQUET = True

pandas/tests/plotting/test_datetimelike.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Index,
2222
NaT,
2323
Series,
24+
concat,
2425
isna,
2526
to_datetime,
2627
)
@@ -244,7 +245,7 @@ def test_fake_inferred_business(self):
244245
_, ax = self.plt.subplots()
245246
rng = date_range("2001-1-1", "2001-1-10")
246247
ts = Series(range(len(rng)), index=rng)
247-
ts = ts[:3].append(ts[5:])
248+
ts = concat([ts[:3], ts[5:]])
248249
ts.plot(ax=ax)
249250
assert not hasattr(ax, "freq")
250251

pandas/tests/test_downstream.py

+4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def test_oo_optimized_datetime_index_unpickle():
103103
# patsy needs to update their imports
104104
"ignore:Using or importing the ABCs from 'collections:DeprecationWarning"
105105
)
106+
@pytest.mark.filterwarnings(
107+
# numpy 1.22
108+
"ignore:`np.MachAr` is deprecated.*:DeprecationWarning"
109+
)
106110
def test_statsmodels():
107111

108112
statsmodels = import_module("statsmodels") # noqa:F841

pandas/util/_test_decorators.py

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def safe_import(mod_name: str, min_version: str | None = None):
7272
message=".*decorator is deprecated since Python 3.8.*",
7373
)
7474

75+
# fastparquet import accesses pd.Int64Index
76+
warnings.filterwarnings(
77+
"ignore",
78+
category=FutureWarning,
79+
module="fastparquet",
80+
message=".*Int64Index.*",
81+
)
82+
7583
try:
7684
mod = __import__(mod_name)
7785
except ImportError:

0 commit comments

Comments
 (0)