diff --git a/pandas/tests/frame/test_repr_info.py b/pandas/tests/frame/test_repr_info.py index c5d4d59adbc35..48cf37a9abc8b 100644 --- a/pandas/tests/frame/test_repr_info.py +++ b/pandas/tests/frame/test_repr_info.py @@ -212,3 +212,8 @@ def test_repr_np_nat_with_object(self, arg, box, expected): # GH 25445 result = repr(box([arg("NaT")], dtype=object)) assert result == expected + + def test_frame_datetime64_pre1900_repr(self): + df = DataFrame({"year": date_range("1/1/1700", periods=50, freq="A-DEC")}) + # it works! + repr(df) diff --git a/pandas/tests/frame/test_timeseries.py b/pandas/tests/frame/test_timeseries.py index d8eeed69d66e2..452af895e4967 100644 --- a/pandas/tests/frame/test_timeseries.py +++ b/pandas/tests/frame/test_timeseries.py @@ -20,11 +20,6 @@ def test_frame_append_datetime64_column(self): df["A"] = rng assert np.issubdtype(df["A"].dtype, np.dtype("M8[ns]")) - def test_frame_datetime64_pre1900_repr(self): - df = DataFrame({"year": date_range("1/1/1700", periods=50, freq="A-DEC")}) - # it works! - repr(df) - def test_frame_append_datetime64_col_other_units(self): n = 100 diff --git a/pandas/tests/series/indexing/test_alter_index.py b/pandas/tests/series/indexing/test_alter_index.py index 05bd967903e9d..a3c431696b689 100644 --- a/pandas/tests/series/indexing/test_alter_index.py +++ b/pandas/tests/series/indexing/test_alter_index.py @@ -523,9 +523,9 @@ def test_drop_unique_and_non_unique_index( ], ) def test_drop_exception_raised(data, index, drop_labels, axis, error_type, error_desc): - + ser = Series(data, index=index) with pytest.raises(error_type, match=error_desc): - Series(data, index=index).drop(drop_labels, axis=axis) + ser.drop(drop_labels, axis=axis) def test_drop_with_ignore_errors(): @@ -565,6 +565,7 @@ def test_drop_empty_list(index, drop_labels): ) def test_drop_non_empty_list(data, index, drop_labels): # GH 21494 and GH 16877 + dtype = object if data is None else None + ser = pd.Series(data=data, index=index, dtype=dtype) with pytest.raises(KeyError, match="not found in axis"): - dtype = object if data is None else None - pd.Series(data=data, index=index, dtype=dtype).drop(drop_labels) + ser.drop(drop_labels) diff --git a/pandas/tests/series/test_repr.py b/pandas/tests/series/test_repr.py index 64a8c4569406e..77f942a9e32ec 100644 --- a/pandas/tests/series/test_repr.py +++ b/pandas/tests/series/test_repr.py @@ -218,6 +218,25 @@ def test_index_repr_in_frame_with_nan(self): assert repr(s) == exp + def test_format_pre_1900_dates(self): + rng = date_range("1/1/1850", "1/1/1950", freq="A-DEC") + rng.format() + ts = Series(1, index=rng) + repr(ts) + + def test_series_repr_nat(self): + series = Series([0, 1000, 2000, pd.NaT.value], dtype="M8[ns]") + + result = repr(series) + expected = ( + "0 1970-01-01 00:00:00.000000\n" + "1 1970-01-01 00:00:00.000001\n" + "2 1970-01-01 00:00:00.000002\n" + "3 NaT\n" + "dtype: datetime64[ns]" + ) + assert result == expected + class TestCategoricalRepr: def test_categorical_repr_unicode(self): diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index 9796a32532b99..563cfa57c9214 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -2,8 +2,6 @@ import numpy as np -from pandas._libs.tslib import iNaT - import pandas as pd from pandas import DataFrame, DatetimeIndex, Series, date_range, timedelta_range import pandas._testing as tm @@ -88,19 +86,6 @@ def test_series_ctor_datetime64(self): series = Series(dates) assert np.issubdtype(series.dtype, np.dtype("M8[ns]")) - def test_series_repr_nat(self): - series = Series([0, 1000, 2000, iNaT], dtype="M8[ns]") - - result = repr(series) - expected = ( - "0 1970-01-01 00:00:00.000000\n" - "1 1970-01-01 00:00:00.000001\n" - "2 1970-01-01 00:00:00.000002\n" - "3 NaT\n" - "dtype: datetime64[ns]" - ) - assert result == expected - def test_promote_datetime_date(self): rng = date_range("1/1/2000", periods=20) ts = Series(np.random.randn(20), index=rng) @@ -124,12 +109,6 @@ def test_promote_datetime_date(self): expected = rng.get_indexer(ts_slice.index) tm.assert_numpy_array_equal(result, expected) - def test_format_pre_1900_dates(self): - rng = date_range("1/1/1850", "1/1/1950", freq="A-DEC") - rng.format() - ts = Series(1, index=rng) - repr(ts) - def test_groupby_count_dateparseerror(self): dr = date_range(start="1/1/2012", freq="5min", periods=10)