From 159ccab7843dd271348c41ee829b8a3ba038f18d Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Fri, 27 Jan 2023 08:08:53 -0500 Subject: [PATCH 1/3] undo patch for nightly not being built --- tests/test_pandas.py | 46 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/test_pandas.py b/tests/test_pandas.py index 3ab353d36..f941f76f4 100644 --- a/tests/test_pandas.py +++ b/tests/test_pandas.py @@ -1705,34 +1705,32 @@ def test_pivot_table() -> None: ), pd.DataFrame, ) - if PD_LTE_15: - # Nightly builds failing since 1/12/2023, but this is fixed since then - check( - assert_type( - pd.pivot_table( - df, - values="D", - index=["A", "B"], - columns=[(7, "seven")], - aggfunc=np.sum, - ), - pd.DataFrame, + check( + assert_type( + pd.pivot_table( + df, + values="D", + index=["A", "B"], + columns=[(7, "seven")], + aggfunc=np.sum, ), pd.DataFrame, - ) - check( - assert_type( - pd.pivot_table( - df, - values="D", - index=[("col5",), ("col6", 6)], - columns=[(7, "seven")], - aggfunc=np.sum, - ), - pd.DataFrame, + ), + pd.DataFrame, + ) + check( + assert_type( + pd.pivot_table( + df, + values="D", + index=[("col5",), ("col6", 6)], + columns=[(7, "seven")], + aggfunc=np.sum, ), pd.DataFrame, - ) + ), + pd.DataFrame, + ) check( assert_type( pd.pivot_table( From aff087b8fc93cb3c142f7ad21b104c9a15d37264 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Fri, 27 Jan 2023 08:46:10 -0500 Subject: [PATCH 2/3] replace IntegerIndex with NumericIndex --- pandas-stubs/core/indexes/accessors.pyi | 12 ++--- tests/test_timefuncs.py | 64 ++++++++++++------------- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/pandas-stubs/core/indexes/accessors.pyi b/pandas-stubs/core/indexes/accessors.pyi index 5097b2061..23e6674d1 100644 --- a/pandas-stubs/core/indexes/accessors.pyi +++ b/pandas-stubs/core/indexes/accessors.pyi @@ -25,7 +25,7 @@ from pandas.core.base import ( PandasObject, ) from pandas.core.frame import DataFrame -from pandas.core.indexes.numeric import IntegerIndex +from pandas.core.indexes.numeric import NumericIndex from pandas.core.series import ( PeriodSeries, Series, @@ -43,14 +43,14 @@ from pandas._typing import ( class Properties(PandasDelegate, PandasObject, NoNewAttributesMixin): def __init__(self, data: Series, orig) -> None: ... -_DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", Series[int], IntegerIndex) +_DTFieldOpsReturnType = TypeVar("_DTFieldOpsReturnType", Series[int], NumericIndex) class _DatetimeFieldOps( _DayLikeFieldOps[_DTFieldOpsReturnType], _MiniSeconds[_DTFieldOpsReturnType] ): ... class PeriodIndexFieldOps( - _DayLikeFieldOps[IntegerIndex], - _PeriodProperties[DatetimeIndex, IntegerIndex, Index, DatetimeIndex, PeriodIndex], + _DayLikeFieldOps[NumericIndex], + _PeriodProperties[DatetimeIndex, NumericIndex, Index, DatetimeIndex, PeriodIndex], ): ... class _DayLikeFieldOps(Generic[_DTFieldOpsReturnType]): @@ -306,7 +306,7 @@ class TimedeltaProperties( ): ... _PeriodDTReturnTypes = TypeVar("_PeriodDTReturnTypes", TimestampSeries, DatetimeIndex) -_PeriodIntReturnTypes = TypeVar("_PeriodIntReturnTypes", Series[int], IntegerIndex) +_PeriodIntReturnTypes = TypeVar("_PeriodIntReturnTypes", Series[int], NumericIndex) _PeriodStrReturnTypes = TypeVar("_PeriodStrReturnTypes", Series[str], Index) _PeriodDTAReturnTypes = TypeVar("_PeriodDTAReturnTypes", DatetimeArray, DatetimeIndex) _PeriodPAReturnTypes = TypeVar("_PeriodPAReturnTypes", PeriodArray, PeriodIndex) @@ -382,7 +382,7 @@ class TimestampProperties( class DatetimeIndexProperties( Properties, _DatetimeNoTZProperties[ - IntegerIndex, + NumericIndex, np_ndarray_bool, DatetimeIndex, np.ndarray, diff --git a/tests/test_timefuncs.py b/tests/test_timefuncs.py index 8eb392333..51418e257 100644 --- a/tests/test_timefuncs.py +++ b/tests/test_timefuncs.py @@ -12,7 +12,7 @@ import numpy as np from numpy import typing as npt import pandas as pd -from pandas.core.indexes.numeric import IntegerIndex +from pandas.core.indexes.numeric import NumericIndex import pytz from typing_extensions import assert_type @@ -441,7 +441,7 @@ def test_series_dt_accessors() -> None: def test_datetimeindex_accessors() -> None: # GH 194 x = pd.DatetimeIndex(["2022-08-14", "2022-08-20"]) - check(assert_type(x.month, IntegerIndex), IntegerIndex) + check(assert_type(x.month, NumericIndex), NumericIndex) i0 = pd.date_range(start="2022-06-01", periods=10) check(assert_type(i0, pd.DatetimeIndex), pd.DatetimeIndex, pd.Timestamp) @@ -449,20 +449,20 @@ def test_datetimeindex_accessors() -> None: check(assert_type(i0.date, np.ndarray), np.ndarray, dt.date) check(assert_type(i0.time, np.ndarray), np.ndarray, dt.time) check(assert_type(i0.timetz, np.ndarray), np.ndarray, dt.time) - check(assert_type(i0.year, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.month, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.day, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.hour, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.minute, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.second, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.microsecond, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.nanosecond, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.dayofweek, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.day_of_week, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.weekday, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.dayofyear, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.day_of_year, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.quarter, IntegerIndex), IntegerIndex, int) + check(assert_type(i0.year, NumericIndex), NumericIndex, int) + check(assert_type(i0.month, NumericIndex), NumericIndex, int) + check(assert_type(i0.day, NumericIndex), NumericIndex, int) + check(assert_type(i0.hour, NumericIndex), NumericIndex, int) + check(assert_type(i0.minute, NumericIndex), NumericIndex, int) + check(assert_type(i0.second, NumericIndex), NumericIndex, int) + check(assert_type(i0.microsecond, NumericIndex), NumericIndex, int) + check(assert_type(i0.nanosecond, NumericIndex), NumericIndex, int) + check(assert_type(i0.dayofweek, NumericIndex), NumericIndex, int) + check(assert_type(i0.day_of_week, NumericIndex), NumericIndex, int) + check(assert_type(i0.weekday, NumericIndex), NumericIndex, int) + check(assert_type(i0.dayofyear, NumericIndex), NumericIndex, int) + check(assert_type(i0.day_of_year, NumericIndex), NumericIndex, int) + check(assert_type(i0.quarter, NumericIndex), NumericIndex, int) check(assert_type(i0.is_month_start, npt.NDArray[np.bool_]), np.ndarray, np.bool_) check(assert_type(i0.is_month_end, npt.NDArray[np.bool_]), np.ndarray, np.bool_) check(assert_type(i0.is_quarter_start, npt.NDArray[np.bool_]), np.ndarray, np.bool_) @@ -470,8 +470,8 @@ def test_datetimeindex_accessors() -> None: check(assert_type(i0.is_year_start, npt.NDArray[np.bool_]), np.ndarray, np.bool_) check(assert_type(i0.is_year_end, npt.NDArray[np.bool_]), np.ndarray, np.bool_) check(assert_type(i0.is_leap_year, npt.NDArray[np.bool_]), np.ndarray, np.bool_) - check(assert_type(i0.daysinmonth, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.days_in_month, IntegerIndex), IntegerIndex, int) + check(assert_type(i0.daysinmonth, NumericIndex), NumericIndex, int) + check(assert_type(i0.days_in_month, NumericIndex), NumericIndex, int) check(assert_type(i0.tz, Optional[dt.tzinfo]), type(None)) check(assert_type(i0.freq, Optional[BaseOffset]), BaseOffset) check(assert_type(i0.isocalendar(), pd.DataFrame), pd.DataFrame) @@ -531,20 +531,20 @@ def test_periodindex_accessors() -> None: i0 = pd.period_range(start="2022-06-01", periods=10) check(assert_type(i0, pd.PeriodIndex), pd.PeriodIndex, pd.Period) - check(assert_type(i0.year, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.month, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.day, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.hour, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.minute, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.second, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.dayofweek, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.day_of_week, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.weekday, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.dayofyear, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.day_of_year, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.quarter, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.daysinmonth, IntegerIndex), IntegerIndex, int) - check(assert_type(i0.days_in_month, IntegerIndex), IntegerIndex, int) + check(assert_type(i0.year, NumericIndex), NumericIndex, int) + check(assert_type(i0.month, NumericIndex), NumericIndex, int) + check(assert_type(i0.day, NumericIndex), NumericIndex, int) + check(assert_type(i0.hour, NumericIndex), NumericIndex, int) + check(assert_type(i0.minute, NumericIndex), NumericIndex, int) + check(assert_type(i0.second, NumericIndex), NumericIndex, int) + check(assert_type(i0.dayofweek, NumericIndex), NumericIndex, int) + check(assert_type(i0.day_of_week, NumericIndex), NumericIndex, int) + check(assert_type(i0.weekday, NumericIndex), NumericIndex, int) + check(assert_type(i0.dayofyear, NumericIndex), NumericIndex, int) + check(assert_type(i0.day_of_year, NumericIndex), NumericIndex, int) + check(assert_type(i0.quarter, NumericIndex), NumericIndex, int) + check(assert_type(i0.daysinmonth, NumericIndex), NumericIndex, int) + check(assert_type(i0.days_in_month, NumericIndex), NumericIndex, int) check(assert_type(i0.freq, Optional[BaseOffset]), BaseOffset) check(assert_type(i0.strftime("%Y"), pd.Index), pd.Index, str) check(assert_type(i0.asfreq("D"), pd.PeriodIndex), pd.PeriodIndex, pd.Period) From 9ff19995d52d5dc0555aab687cdbbb8d0644a0dd Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Fri, 27 Jan 2023 08:58:01 -0500 Subject: [PATCH 3/3] fix to_latex test for nightly --- tests/test_frame.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/test_frame.py b/tests/test_frame.py index 527e3ff5a..131f4ed98 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -1310,17 +1310,25 @@ def test_types_to_parquet() -> None: def test_types_to_latex() -> None: df = pd.DataFrame([[1, 2], [8, 9]], columns=["A", "B"]) - with pytest.warns(FutureWarning, match="In future versions `DataFrame.to_latex`"): + with pytest_warns_bounded( + FutureWarning, match="In future versions `DataFrame.to_latex`", upper="1.5.999" + ): df.to_latex( columns=["A"], label="some_label", caption="some_caption", multirow=True ) - with pytest.warns(FutureWarning, match="In future versions `DataFrame.to_latex`"): + with pytest_warns_bounded( + FutureWarning, match="In future versions `DataFrame.to_latex`", upper="1.5.999" + ): df.to_latex(escape=False, decimal=",", column_format="r") # position param was added in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html - with pytest.warns(FutureWarning, match="In future versions `DataFrame.to_latex`"): + with pytest_warns_bounded( + FutureWarning, match="In future versions `DataFrame.to_latex`", upper="1.5.999" + ): df.to_latex(position="some") # caption param was extended to accept tuple in 1.2.0 https://pandas.pydata.org/docs/whatsnew/v1.2.0.html - with pytest.warns(FutureWarning, match="In future versions `DataFrame.to_latex`"): + with pytest_warns_bounded( + FutureWarning, match="In future versions `DataFrame.to_latex`", upper="1.5.999" + ): df.to_latex(caption=("cap1", "cap2"))