From 7daf53571cf6268dfd87e50d2dc64f08ce716fea Mon Sep 17 00:00:00 2001 From: Patrick Hoefler <61934744+phofl@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:17:58 +0100 Subject: [PATCH] Fixup tests --- pandas/_testing/__init__.py | 13 ++++++++++--- pandas/tests/tseries/frequencies/test_inference.py | 4 +++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index b1918e1b1d7c2..3a1aae47c5eba 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -15,6 +15,7 @@ ContextManager, cast, ) +import warnings import numpy as np @@ -306,11 +307,17 @@ def box_expected(expected, box_cls, transpose: bool = True): else: expected = pd.array(expected, copy=False) elif box_cls is Index: - expected = Index(expected) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Dtype inference", category=FutureWarning) + expected = Index(expected) elif box_cls is Series: - expected = Series(expected) + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Dtype inference", category=FutureWarning) + expected = Series(expected) elif box_cls is DataFrame: - expected = Series(expected).to_frame() + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", "Dtype inference", category=FutureWarning) + expected = Series(expected).to_frame() if transpose: # for vector operations, we need a DataFrame to be a single-row, # not a single-column, in order to operate against non-DataFrame diff --git a/pandas/tests/tseries/frequencies/test_inference.py b/pandas/tests/tseries/frequencies/test_inference.py index 45741e852fef7..99a504f4188c1 100644 --- a/pandas/tests/tseries/frequencies/test_inference.py +++ b/pandas/tests/tseries/frequencies/test_inference.py @@ -23,6 +23,7 @@ date_range, period_range, ) +import pandas._testing as tm from pandas.core.arrays import ( DatetimeArray, TimedeltaArray, @@ -206,7 +207,8 @@ def test_infer_freq_custom(base_delta_code_pair, constructor): ) def test_infer_freq_index(freq, expected): rng = period_range("1959Q2", "2009Q3", freq=freq) - rng = Index(rng.to_timestamp("D", how="e").astype(object)) + with tm.assert_produces_warning(FutureWarning, match="Dtype inference"): + rng = Index(rng.to_timestamp("D", how="e").astype(object)) assert rng.inferred_freq == expected