diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4285dd7fa..585ac7bb8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,11 +7,11 @@ repos: hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.0 hooks: - id: isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.6 + rev: v0.1.7 hooks: - id: ruff args: [ diff --git a/pandas-stubs/_testing/__init__.pyi b/pandas-stubs/_testing/__init__.pyi index 0c91b28f7..aba20f5de 100644 --- a/pandas-stubs/_testing/__init__.pyi +++ b/pandas-stubs/_testing/__init__.pyi @@ -12,7 +12,6 @@ from pandas import ( Series, ) -def getSeriesData(): ... def assert_almost_equal( left, right, diff --git a/pandas-stubs/api/types/__init__.pyi b/pandas-stubs/api/types/__init__.pyi index bfdaa105b..8f5f9cbf1 100644 --- a/pandas-stubs/api/types/__init__.pyi +++ b/pandas-stubs/api/types/__init__.pyi @@ -5,13 +5,11 @@ from pandas.core.dtypes.api import ( is_array_like as is_array_like, is_bool as is_bool, is_bool_dtype as is_bool_dtype, - is_categorical_dtype as is_categorical_dtype, is_complex as is_complex, is_complex_dtype as is_complex_dtype, is_datetime64_any_dtype as is_datetime64_any_dtype, is_datetime64_dtype as is_datetime64_dtype, is_datetime64_ns_dtype as is_datetime64_ns_dtype, - is_datetime64tz_dtype as is_datetime64tz_dtype, is_dict_like as is_dict_like, is_dtype_equal as is_dtype_equal, is_extension_array_dtype as is_extension_array_dtype, @@ -19,23 +17,19 @@ from pandas.core.dtypes.api import ( is_float as is_float, is_float_dtype as is_float_dtype, is_hashable as is_hashable, - is_int64_dtype as is_int64_dtype, is_integer as is_integer, is_integer_dtype as is_integer_dtype, is_interval as is_interval, - is_interval_dtype as is_interval_dtype, is_iterator as is_iterator, is_list_like as is_list_like, is_named_tuple as is_named_tuple, is_number as is_number, is_numeric_dtype as is_numeric_dtype, is_object_dtype as is_object_dtype, - is_period_dtype as is_period_dtype, is_re as is_re, is_re_compilable as is_re_compilable, is_scalar as is_scalar, is_signed_integer_dtype as is_signed_integer_dtype, - is_sparse as is_sparse, is_string_dtype as is_string_dtype, is_timedelta64_dtype as is_timedelta64_dtype, is_timedelta64_ns_dtype as is_timedelta64_ns_dtype, diff --git a/pandas-stubs/core/dtypes/api.pyi b/pandas-stubs/core/dtypes/api.pyi index e52ace018..419b16466 100644 --- a/pandas-stubs/core/dtypes/api.pyi +++ b/pandas-stubs/core/dtypes/api.pyi @@ -3,13 +3,11 @@ from pandas.core.dtypes.common import ( is_array_like as is_array_like, is_bool as is_bool, is_bool_dtype as is_bool_dtype, - is_categorical_dtype as is_categorical_dtype, is_complex as is_complex, is_complex_dtype as is_complex_dtype, is_datetime64_any_dtype as is_datetime64_any_dtype, is_datetime64_dtype as is_datetime64_dtype, is_datetime64_ns_dtype as is_datetime64_ns_dtype, - is_datetime64tz_dtype as is_datetime64tz_dtype, is_dict_like as is_dict_like, is_dtype_equal as is_dtype_equal, is_extension_array_dtype as is_extension_array_dtype, @@ -17,23 +15,19 @@ from pandas.core.dtypes.common import ( is_float as is_float, is_float_dtype as is_float_dtype, is_hashable as is_hashable, - is_int64_dtype as is_int64_dtype, is_integer as is_integer, is_integer_dtype as is_integer_dtype, is_interval as is_interval, - is_interval_dtype as is_interval_dtype, is_iterator as is_iterator, is_list_like as is_list_like, is_named_tuple as is_named_tuple, is_number as is_number, is_numeric_dtype as is_numeric_dtype, is_object_dtype as is_object_dtype, - is_period_dtype as is_period_dtype, is_re as is_re, is_re_compilable as is_re_compilable, is_scalar as is_scalar, is_signed_integer_dtype as is_signed_integer_dtype, - is_sparse as is_sparse, is_string_dtype as is_string_dtype, is_timedelta64_dtype as is_timedelta64_dtype, is_timedelta64_ns_dtype as is_timedelta64_ns_dtype, diff --git a/pandas-stubs/core/dtypes/common.pyi b/pandas-stubs/core/dtypes/common.pyi index 8a0a95edc..75b5cdd2a 100644 --- a/pandas-stubs/core/dtypes/common.pyi +++ b/pandas-stubs/core/dtypes/common.pyi @@ -32,19 +32,13 @@ _ArrayOrDtype: TypeAlias = ( ) def is_object_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... -def is_sparse(arr: ArrayLike | pd.Series | pd.DataFrame) -> bool: ... def is_datetime64_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... -def is_datetime64tz_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_timedelta64_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... -def is_period_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_dtype_equal(source, target) -> bool: ... -def is_interval_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... -def is_categorical_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_string_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_integer_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_signed_integer_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_unsigned_integer_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... -def is_int64_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_datetime64_any_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_datetime64_ns_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... def is_timedelta64_ns_dtype(arr_or_dtype: _ArrayOrDtype) -> bool: ... diff --git a/pandas-stubs/io/excel/_base.pyi b/pandas-stubs/io/excel/_base.pyi index 539ed1cf3..28e8a2468 100644 --- a/pandas-stubs/io/excel/_base.pyi +++ b/pandas-stubs/io/excel/_base.pyi @@ -36,7 +36,6 @@ from pandas._typing import ( def read_excel( io: FilePath | ReadBuffer[bytes] - | bytes | ExcelFile | Workbook | Book @@ -75,7 +74,6 @@ def read_excel( def read_excel( io: FilePath | ReadBuffer[bytes] - | bytes | ExcelFile | Workbook | Book @@ -115,7 +113,6 @@ def read_excel( def read_excel( # type: ignore[misc] io: FilePath | ReadBuffer[bytes] - | bytes | ExcelFile | Workbook | Book @@ -154,7 +151,6 @@ def read_excel( # type: ignore[misc] def read_excel( io: FilePath | ReadBuffer[bytes] - | bytes | ExcelFile | Workbook | Book diff --git a/tests/test_api_types.py b/tests/test_api_types.py index f4088692e..0ebb37cce 100644 --- a/tests/test_api_types.py +++ b/tests/test_api_types.py @@ -52,18 +52,6 @@ def test_is_bool_dtype() -> None: check(assert_type(api.is_bool_dtype(ExtensionDtype), bool), bool) -def test_is_categorical_dtype() -> None: - with pytest_warns_bounded( - FutureWarning, "is_categorical_dtype is deprecated", lower="2.0.99" - ): - check(assert_type(api.is_categorical_dtype(arr), bool), bool) - check(assert_type(api.is_categorical_dtype(nparr), bool), bool) - check(assert_type(api.is_categorical_dtype(dtylike), bool), bool) - check(assert_type(api.is_categorical_dtype(dframe), bool), bool) - check(assert_type(api.is_categorical_dtype(ind), bool), bool) - check(assert_type(api.is_categorical_dtype(ExtensionDtype), bool), bool) - - def test_is_complex() -> None: check(assert_type(api.is_complex(obj), bool), bool) check(assert_type(api.is_complex(nparr), bool), bool) @@ -124,18 +112,6 @@ def test_is_datetime64_ns_dtype() -> None: check(assert_type(api.is_datetime64_ns_dtype(ExtensionDtype), bool), bool) -def test_is_datetime64tz_dtype() -> None: - with pytest_warns_bounded( - FutureWarning, "is_datetime64tz_dtype is deprecated", lower="2.0.99" - ): - check(assert_type(api.is_datetime64tz_dtype(arr), bool), bool) - check(assert_type(api.is_datetime64tz_dtype(nparr), bool), bool) - check(assert_type(api.is_datetime64tz_dtype(dtylike), bool), bool) - check(assert_type(api.is_datetime64tz_dtype(dframe), bool), bool) - check(assert_type(api.is_datetime64tz_dtype(ind), bool), bool) - check(assert_type(api.is_datetime64tz_dtype(ExtensionDtype), bool), bool) - - def test_is_dict_like() -> None: check(assert_type(api.is_dict_like(mapping), bool), bool) check(assert_type(api.is_dict_like(nparr), bool), bool) @@ -209,18 +185,6 @@ def test_is_hashable() -> None: check(assert_type(api.is_hashable(ind), bool), bool) -def test_is_int64_dtype() -> None: - with pytest_warns_bounded( - FutureWarning, "is_int64_dtype is deprecated", lower="2.0.99" - ): - check(assert_type(api.is_int64_dtype(arr), bool), bool) - check(assert_type(api.is_int64_dtype(nparr), bool), bool) - check(assert_type(api.is_int64_dtype(dtylike), bool), bool) - check(assert_type(api.is_int64_dtype(dframe), bool), bool) - check(assert_type(api.is_int64_dtype(ind), bool), bool) - # check(assert_type(api.is_int64_dtype(ExtensionDtype), bool), bool) pandas GH 50923 - - def test_is_integer() -> None: check(assert_type(api.is_integer(obj), bool), bool) check(assert_type(api.is_integer(nparr), bool), bool) @@ -260,19 +224,6 @@ def test_is_interval() -> None: check(assert_type(api.is_interval(ind), bool), bool) -def test_is_interval_dtype() -> None: - with pytest_warns_bounded( - FutureWarning, "is_interval_dtype is deprecated", lower="2.0.99" - ): - check(assert_type(api.is_interval_dtype(obj), bool), bool) - check(assert_type(api.is_interval_dtype(nparr), bool), bool) - check(assert_type(api.is_interval_dtype(dtylike), bool), bool) - check(assert_type(api.is_interval_dtype(arr), bool), bool) - check(assert_type(api.is_interval_dtype(dframe), bool), bool) - check(assert_type(api.is_interval_dtype(ind), bool), bool) - check(assert_type(api.is_interval_dtype(ExtensionDtype), bool), bool) - - def test_is_iterator() -> None: check(assert_type(api.is_iterator(obj), bool), bool) check(assert_type(api.is_iterator(nparr), bool), bool) @@ -342,18 +293,6 @@ def test_is_object_dtype() -> None: # check(assert_type(api.is_object_dtype(ExtensionDtype), bool), bool) pandas GH 50923 -def test_is_period_dtype() -> None: - with pytest_warns_bounded( - FutureWarning, "is_period_dtype is deprecated", lower="2.0.99" - ): - check(assert_type(api.is_period_dtype(arr), bool), bool) - check(assert_type(api.is_period_dtype(nparr), bool), bool) - check(assert_type(api.is_period_dtype(dtylike), bool), bool) - check(assert_type(api.is_period_dtype(dframe), bool), bool) - check(assert_type(api.is_period_dtype(ind), bool), bool) - check(assert_type(api.is_period_dtype(ExtensionDtype), bool), bool) - - def test_is_re() -> None: check(assert_type(api.is_re(obj), bool), bool) check(assert_type(api.is_re(nparr), bool), bool) @@ -396,13 +335,6 @@ def test_is_signed_integer_dtype() -> None: # check(assert_type(api.is_signed_integer_dtype(ExtensionDtype), bool), bool) pandas GH 50923 -def test_is_sparse() -> None: - with pytest_warns_bounded(FutureWarning, "is_sparse is deprecated", lower="2.0.99"): - check(assert_type(api.is_sparse(arr), bool), bool) - check(assert_type(api.is_sparse(nparr), bool), bool) - check(assert_type(api.is_sparse(dframe), bool), bool) - - def test_is_string_dtype() -> None: check(assert_type(api.is_string_dtype(arr), bool), bool) check(assert_type(api.is_string_dtype(nparr), bool), bool) diff --git a/tests/test_frame.py b/tests/test_frame.py index 9bc32ddba..a25e9b683 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -14,6 +14,7 @@ import io import itertools from pathlib import Path +import string from typing import ( TYPE_CHECKING, Any, @@ -28,10 +29,7 @@ import numpy as np import numpy.typing as npt import pandas as pd -from pandas._testing import ( - ensure_clean, - getSeriesData, -) +from pandas._testing import ensure_clean from pandas.core.resample import Resampler # noqa: F401 from pandas.core.series import Series import pytest @@ -52,6 +50,36 @@ DF = pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}) +def getCols(k) -> str: + return string.ascii_uppercase[:k] + + +def makeStringIndex(k: int = 10) -> pd.Index: + return pd.Index(rands_array(nchars=10, size=k), name=None) + + +def rands_array(nchars, size: int) -> np.ndarray: + chars = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1)) + retval = ( + np.random.default_rng(2) + .choice(chars, size=nchars * np.prod(size), replace=True) + .view((np.str_, nchars)) + .reshape(size) + ) + return retval.astype("O") + + +def getSeriesData() -> dict[str, pd.Series]: + _N = 30 + _K = 4 + + index = makeStringIndex(_N) + return { + c: pd.Series(np.random.default_rng(i).standard_normal(_N), index=index) + for i, c in enumerate(getCols(_K)) + } + + def test_types_init() -> None: pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}) pd.DataFrame(data={"col1": [1, 2], "col2": [3, 4]}, index=[2, 1]) diff --git a/tests/test_io.py b/tests/test_io.py index 4a46d1476..ea3d96006 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -469,8 +469,17 @@ def test_hdf_series(): def test_spss(): path = Path(CWD, "data", "labelled-num.sav") - check(assert_type(read_spss(path, convert_categoricals=True), DataFrame), DataFrame) - check(assert_type(read_spss(str(path), usecols=["VAR00002"]), DataFrame), DataFrame) + with pytest_warns_bounded( + FutureWarning, "ChainedAssignmentError: behaviour will change", lower="2.1.99" + ): + check( + assert_type(read_spss(path, convert_categoricals=True), DataFrame), + DataFrame, + ) + check( + assert_type(read_spss(str(path), usecols=["VAR00002"]), DataFrame), + DataFrame, + ) def test_json(): @@ -1022,14 +1031,6 @@ def test_read_excel_io_types() -> None: with as_path.open("rb") as as_file: check(assert_type(pd.read_excel(as_file), pd.DataFrame), pd.DataFrame) - as_bytes = as_path.read_bytes() - with pytest_warns_bounded( - FutureWarning, - "Passing bytes to 'read_excel' is deprecated", - lower="2.0.99", - ): - check(assert_type(pd.read_excel(as_bytes), pd.DataFrame), pd.DataFrame) - def test_read_excel_basic(): with ensure_clean(".xlsx") as path: diff --git a/tests/test_scalars.py b/tests/test_scalars.py index b308965cb..220aadd28 100644 --- a/tests/test_scalars.py +++ b/tests/test_scalars.py @@ -844,7 +844,10 @@ def test_timedelta_cmp() -> None: c_dt_timedelta = dt.timedelta(days=1) c_timedelta64 = np.timedelta64(1, "D") c_ndarray_td64 = ndarray_td64 - c_timedelta_index = pd.TimedeltaIndex([1, 2, 3], unit="D") + with pytest_warns_bounded( + FutureWarning, "The 'unit' keyword in TimedeltaIndex", lower="2.1.99" + ): + c_timedelta_index = pd.TimedeltaIndex([1, 2, 3], unit="D") c_timedelta_series = pd.Series(pd.TimedeltaIndex([1, 2, 3])) check(assert_type(td < c_timedelta, bool), bool) @@ -1047,7 +1050,10 @@ def test_timedelta_cmp_rhs() -> None: c_dt_timedelta = dt.timedelta(days=1) c_timedelta64 = np.timedelta64(1, "D") c_ndarray_td64 = ndarray_td64 - c_timedelta_index = pd.TimedeltaIndex([1, 2, 3], unit="D") + with pytest_warns_bounded( + FutureWarning, "The 'unit' keyword in TimedeltaIndex", lower="2.1.99" + ): + c_timedelta_index = pd.TimedeltaIndex([1, 2, 3], unit="D") c_timedelta_series = pd.Series(pd.TimedeltaIndex([1, 2, 3])) eq = check(assert_type(c_dt_timedelta == td, bool), bool) @@ -1192,7 +1198,11 @@ def test_timestamp_add_sub() -> None: as_pd_timedelta = pd.Timedelta(days=1) as_dt_timedelta = dt.timedelta(days=1) as_offset = 3 * Day() - as_timedelta_index = pd.TimedeltaIndex([1, 2, 3], "D") + + with pytest_warns_bounded( + FutureWarning, "The 'unit' keyword in TimedeltaIndex", lower="2.1.99" + ): + as_timedelta_index = pd.TimedeltaIndex([1, 2, 3], "D") as_timedelta_series = pd.Series(as_timedelta_index) check(assert_type(as_timedelta_series, TimedeltaSeries), pd.Series, pd.Timedelta) as_np_ndarray_td64 = np_td64_arr