diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 3ee34a158902b..a12fbcd549bd1 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -815,7 +815,7 @@ Indexing Missing ^^^^^^^ -- Bug in :meth:`DataFrame.fillna` with limit and no method ignores axis='columns' or ``axis = 1`` (:issue:`40989`) +- Bug in :meth:`DataFrame.fillna` with limit and no method ignores axis='columns' or ``axis = 1`` (:issue:`40989`, :issue:`17399`) - Bug in :meth:`DataFrame.fillna` not replacing missing values when using a dict-like ``value`` and duplicate column names (:issue:`43476`) - 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`) - Bug in :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` with ``inplace=True`` not writing to the underlying array(s) in-place (:issue:`44749`) diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 950277ce608eb..ee317814bf79b 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -714,7 +714,7 @@ cpdef ndarray[object] ensure_string_array( return out arr = arr.to_numpy() - elif not isinstance(arr, np.ndarray): + elif not util.is_array(arr): arr = np.array(arr, dtype="object") result = np.asarray(arr, dtype="object") @@ -729,7 +729,7 @@ cpdef ndarray[object] ensure_string_array( continue if not checknull(val): - if not isinstance(val, np.floating): + if not util.is_float_object(val): # f"{val}" is faster than str(val) result[i] = f"{val}" else: diff --git a/pandas/core/arrays/masked.py b/pandas/core/arrays/masked.py index 065e10f3c49ba..3d80a544b41fb 100644 --- a/pandas/core/arrays/masked.py +++ b/pandas/core/arrays/masked.py @@ -767,7 +767,7 @@ def _quantile( We assume that all impacted cases are 1D-only. """ mask = np.atleast_2d(np.asarray(self.isna())) - npvalues = np.atleast_2d(np.asarray(self)) + npvalues: np.ndarray = np.atleast_2d(np.asarray(self)) res = quantile_with_mask( npvalues, diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 14cd725c8f066..aad66747a648b 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -459,7 +459,7 @@ def ensure_dtype_can_hold_na(dtype: DtypeObj) -> DtypeObj: # TODO: ExtensionDtype.can_hold_na? return dtype elif dtype.kind == "b": - return np.dtype(object) + return _dtype_obj elif dtype.kind in ["i", "u"]: return np.dtype(np.float64) return dtype @@ -522,7 +522,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan): # with object dtype there is nothing to promote, and the user can # pass pretty much any weird fill_value they like raise ValueError("fill_value must be a scalar") - dtype = np.dtype(object) + dtype = _dtype_obj return dtype, fill_value kinds = ["i", "u", "f", "c", "m", "M"] @@ -532,7 +532,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan): return dtype, fv elif isna(fill_value): - dtype = np.dtype(object) + dtype = _dtype_obj if fill_value is None: # but we retain e.g. pd.NA fill_value = np.nan @@ -551,7 +551,7 @@ def _maybe_promote(dtype: np.dtype, fill_value=np.nan): # fv = dta._validate_setitem_value(fill_value) # return dta.dtype, fv # except (ValueError, TypeError): - # return np.dtype(object), fill_value + # return _dtype_obj, fill_value if isinstance(fill_value, date) and not isinstance(fill_value, datetime): # deprecate casting of date object to match infer_dtype_from_scalar # and DatetimeArray._validate_setitem_value @@ -699,7 +699,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj, If False, scalar belongs to pandas extension types is inferred as object """ - dtype: DtypeObj = np.dtype(object) + dtype: DtypeObj = _dtype_obj # a 1-element ndarray if isinstance(val, np.ndarray): @@ -718,13 +718,13 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj, # instead of np.empty (but then you still don't want things # coming out as np.str_! - dtype = np.dtype(object) + dtype = _dtype_obj elif isinstance(val, (np.datetime64, datetime)): try: val = Timestamp(val) except OutOfBoundsDatetime: - return np.dtype(object), val + return _dtype_obj, val # error: Non-overlapping identity check (left operand type: "Timestamp", # right operand type: "NaTType") @@ -736,13 +736,13 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False) -> tuple[DtypeObj, dtype = DatetimeTZDtype(unit="ns", tz=val.tz) else: # return datetimetz as object - return np.dtype(object), val + return _dtype_obj, val elif isinstance(val, (np.timedelta64, timedelta)): try: val = Timedelta(val) except (OutOfBoundsTimedelta, OverflowError): - dtype = np.dtype(object) + dtype = _dtype_obj else: dtype = np.dtype("m8[ns]") val = np.timedelta64(val.value, "ns") @@ -1911,7 +1911,7 @@ def construct_1d_arraylike_from_scalar( try: dtype, value = infer_dtype_from_scalar(value, pandas_dtype=True) except OutOfBoundsDatetime: - dtype = np.dtype(object) + dtype = _dtype_obj if isinstance(dtype, ExtensionDtype): cls = dtype.construct_array_type() diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 0ac44ba53ae05..8f8e2417e4c3f 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -4,6 +4,7 @@ from typing import ( TYPE_CHECKING, Hashable, + Sequence, ) import warnings @@ -2016,6 +2017,7 @@ def _ensure_iterable_column_indexer(self, column_indexer): """ Ensure that our column indexer is something that can be iterated over. """ + ilocs: Sequence[int] if is_integer(column_indexer): ilocs = [column_indexer] elif isinstance(column_indexer, slice): diff --git a/pandas/core/internals/array_manager.py b/pandas/core/internals/array_manager.py index ec3a9e8b493e3..4bd8c70bd84ef 100644 --- a/pandas/core/internals/array_manager.py +++ b/pandas/core/internals/array_manager.py @@ -1203,7 +1203,7 @@ def make_empty(self, axes=None) -> SingleArrayManager: """Return an empty ArrayManager with index/array of length 0""" if axes is None: axes = [Index([], dtype=object)] - array = np.array([], dtype=self.dtype) + array: np.ndarray = np.array([], dtype=self.dtype) return type(self)([array], axes) @classmethod diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index 3e0b62da64f42..0e34a098346e7 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1090,14 +1090,12 @@ def iset( # containing (self._blknos[loc], BlockPlacement(slice(0, 1, 1))) # Check if we can use _iset_single fastpath + loc = cast(int, loc) blkno = self.blknos[loc] blk = self.blocks[blkno] if len(blk._mgr_locs) == 1: # TODO: fastest way to check this? return self._iset_single( - # error: Argument 1 to "_iset_single" of "BlockManager" has - # incompatible type "Union[int, slice, ndarray[Any, Any]]"; - # expected "int" - loc, # type:ignore[arg-type] + loc, value, inplace=inplace, blkno=blkno, diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index d043e3ad53f9a..5fc14dc15389b 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -1025,7 +1025,7 @@ def get_empty_frame(data) -> DataFrame: if isinstance(data, Series): index = data.index else: - index = np.arange(len(data)) + index = Index(range(len(data))) return DataFrame(index=index) # if all NaN @@ -1035,7 +1035,7 @@ def get_empty_frame(data) -> DataFrame: codes = codes.copy() if dummy_na: codes[codes == -1] = len(levels) - levels = np.append(levels, np.nan) + levels = levels.insert(len(levels), np.nan) # if dummy_na, we just fake a nan level. drop_first will drop it again if drop_first and len(levels) == 1: diff --git a/pandas/tests/frame/test_ufunc.py b/pandas/tests/frame/test_ufunc.py index 90b4afd657131..bcfcc084bd302 100644 --- a/pandas/tests/frame/test_ufunc.py +++ b/pandas/tests/frame/test_ufunc.py @@ -269,6 +269,11 @@ def test_alignment_deprecation_many_inputs(request): ) request.node.add_marker(mark) + mark = pytest.mark.filterwarnings( + "ignore:`np.MachAr` is deprecated.*:DeprecationWarning" + ) + request.node.add_marker(mark) + @vectorize([float64(float64, float64, float64)]) def my_ufunc(x, y, z): return x + y + z diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 0bd291cea894e..ea88454ce7963 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -43,6 +43,9 @@ with catch_warnings(): # `np.bool` is a deprecated alias... filterwarnings("ignore", "`np.bool`", category=DeprecationWarning) + # accessing pd.Int64Index in pd namespace + filterwarnings("ignore", ".*Int64Index.*", category=FutureWarning) + import fastparquet _HAVE_FASTPARQUET = True diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 44113d1e217fd..8fcd0283d6a98 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -21,6 +21,7 @@ Index, NaT, Series, + concat, isna, to_datetime, ) @@ -244,7 +245,7 @@ def test_fake_inferred_business(self): _, ax = self.plt.subplots() rng = date_range("2001-1-1", "2001-1-10") ts = Series(range(len(rng)), index=rng) - ts = ts[:3].append(ts[5:]) + ts = concat([ts[:3], ts[5:]]) ts.plot(ax=ax) assert not hasattr(ax, "freq") diff --git a/pandas/tests/test_downstream.py b/pandas/tests/test_downstream.py index 3880b9ecd9da7..f1db4a2fc22cb 100644 --- a/pandas/tests/test_downstream.py +++ b/pandas/tests/test_downstream.py @@ -103,6 +103,10 @@ def test_oo_optimized_datetime_index_unpickle(): # patsy needs to update their imports "ignore:Using or importing the ABCs from 'collections:DeprecationWarning" ) +@pytest.mark.filterwarnings( + # numpy 1.22 + "ignore:`np.MachAr` is deprecated.*:DeprecationWarning" +) def test_statsmodels(): statsmodels = import_module("statsmodels") # noqa:F841 diff --git a/pandas/util/_test_decorators.py b/pandas/util/_test_decorators.py index 7c5c0959ceaa0..33bde4e69b042 100644 --- a/pandas/util/_test_decorators.py +++ b/pandas/util/_test_decorators.py @@ -72,6 +72,14 @@ def safe_import(mod_name: str, min_version: str | None = None): message=".*decorator is deprecated since Python 3.8.*", ) + # fastparquet import accesses pd.Int64Index + warnings.filterwarnings( + "ignore", + category=FutureWarning, + module="fastparquet", + message=".*Int64Index.*", + ) + try: mod = __import__(mod_name) except ImportError: