From a50975356688ed85682b78a2ece9bab43574cc58 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 28 Apr 2020 17:48:59 -0700 Subject: [PATCH 1/2] TST: xfail instead of silently passing, dynamic xfail --- pandas/tests/indexing/test_coercion.py | 75 ++++++++++++++------------ 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 5b73118cfdc0c..5cc2399b6ed72 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -102,14 +102,15 @@ def test_setitem_series_object(self, val, exp_dtype): "val,exp_dtype", [(1, np.int64), (1.1, np.float64), (1 + 1j, np.complex128), (True, np.object)], ) - def test_setitem_series_int64(self, val, exp_dtype): + def test_setitem_series_int64(self, val, exp_dtype, request): obj = pd.Series([1, 2, 3, 4]) assert obj.dtype == np.int64 if exp_dtype is np.float64: exp = pd.Series([1, 1, 3, 4]) self._assert_setitem_series_conversion(obj, 1.1, exp, np.int64) - pytest.xfail("GH12747 The result must be float") + mark = pytest.mark.xfail(reason="GH12747 The result must be float") + request.node.add_marker(mark) exp = pd.Series([1, val, 3, 4]) self._assert_setitem_series_conversion(obj, val, exp, exp_dtype) @@ -117,14 +118,17 @@ def test_setitem_series_int64(self, val, exp_dtype): @pytest.mark.parametrize( "val,exp_dtype", [(np.int32(1), np.int8), (np.int16(2 ** 9), np.int16)] ) - def test_setitem_series_int8(self, val, exp_dtype): + def test_setitem_series_int8(self, val, exp_dtype, request): obj = pd.Series([1, 2, 3, 4], dtype=np.int8) assert obj.dtype == np.int8 if exp_dtype is np.int16: exp = pd.Series([1, 0, 3, 4], dtype=np.int8) self._assert_setitem_series_conversion(obj, val, exp, np.int8) - pytest.xfail("BUG: it must be Series([1, 1, 3, 4], dtype=np.int16") + mark = pytest.mark.xfail( + reason="BUG: it must be Series([1, 1, 3, 4], dtype=np.int16" + ) + request.node.add_marker(mark) exp = pd.Series([1, val, 3, 4], dtype=np.int8) self._assert_setitem_series_conversion(obj, val, exp, exp_dtype) @@ -171,22 +175,25 @@ def test_setitem_series_complex128(self, val, exp_dtype): (True, np.bool), ], ) - def test_setitem_series_bool(self, val, exp_dtype): + def test_setitem_series_bool(self, val, exp_dtype, request): obj = pd.Series([True, False, True, False]) assert obj.dtype == np.bool + mark = None if exp_dtype is np.int64: exp = pd.Series([True, True, True, False]) self._assert_setitem_series_conversion(obj, val, exp, np.bool) - pytest.xfail("TODO_GH12747 The result must be int") + mark = pytest.mark.xfail(reason="TODO_GH12747 The result must be int") elif exp_dtype is np.float64: exp = pd.Series([True, True, True, False]) self._assert_setitem_series_conversion(obj, val, exp, np.bool) - pytest.xfail("TODO_GH12747 The result must be float") + mark = pytest.mark.xfail(reason="TODO_GH12747 The result must be float") elif exp_dtype is np.complex128: exp = pd.Series([True, True, True, False]) self._assert_setitem_series_conversion(obj, val, exp, np.bool) - pytest.xfail("TODO_GH12747 The result must be complex") + mark = pytest.mark.xfail(reason="TODO_GH12747 The result must be complex") + if mark is not None: + request.node.add_marker(mark) exp = pd.Series([True, val, True, False]) self._assert_setitem_series_conversion(obj, val, exp, exp_dtype) @@ -318,7 +325,7 @@ def test_setitem_index_int64(self, val, exp_dtype): @pytest.mark.parametrize( "val,exp_dtype", [(5, IndexError), (5.1, np.float64), ("x", np.object)] ) - def test_setitem_index_float64(self, val, exp_dtype): + def test_setitem_index_float64(self, val, exp_dtype, request): obj = pd.Series([1, 2, 3, 4], index=[1.1, 2.1, 3.1, 4.1]) assert obj.index.dtype == np.float64 @@ -327,31 +334,31 @@ def test_setitem_index_float64(self, val, exp_dtype): temp = obj.copy() with pytest.raises(exp_dtype): temp[5] = 5 - pytest.xfail("TODO_GH12747 The result must be float") - + mark = pytest.mark.xfail(reason="TODO_GH12747 The result must be float") + request.node.add_marker(mark) exp_index = pd.Index([1.1, 2.1, 3.1, 4.1, val]) self._assert_setitem_index_conversion(obj, val, exp_index, exp_dtype) def test_setitem_series_period(self): - pass + pytest.xfail("Test not implemented") def test_setitem_index_complex128(self): - pass + pytest.xfail("Test not implemented") def test_setitem_index_bool(self): - pass + pytest.xfail("Test not implemented") def test_setitem_index_datetime64(self): - pass + pytest.xfail("Test not implemented") def test_setitem_index_datetime64tz(self): - pass + pytest.xfail("Test not implemented") def test_setitem_index_timedelta64(self): - pass + pytest.xfail("Test not implemented") def test_setitem_index_period(self): - pass + pytest.xfail("Test not implemented") class TestInsertIndexCoercion(CoercionBase): @@ -503,10 +510,10 @@ def test_insert_index_period(self, insert, coerced_val, coerced_dtype): pd.Index(data, freq="M") def test_insert_index_complex128(self): - pass + pytest.xfail("Test not implemented") def test_insert_index_bool(self): - pass + pytest.xfail("Test not implemented") class TestWhereCoercion(CoercionBase): @@ -757,16 +764,16 @@ def test_where_index_datetime64tz(self): self._assert_where_conversion(obj, cond, values, exp, exp_dtype) def test_where_index_complex128(self): - pass + pytest.xfail("Test not implemented") def test_where_index_bool(self): - pass + pytest.xfail("Test not implemented") def test_where_series_timedelta64(self): - pass + pytest.xfail("Test not implemented") def test_where_series_period(self): - pass + pytest.xfail("Test not implemented") @pytest.mark.parametrize( "value", [pd.Timedelta(days=9), timedelta(days=9), np.timedelta64(9, "D")] @@ -818,7 +825,7 @@ class TestFillnaSeriesCoercion(CoercionBase): method = "fillna" def test_has_comprehensive_tests(self): - pass + pytest.xfail("Test not implemented") def _assert_fillna_conversion(self, original, value, expected, expected_dtype): """ test coercion triggered by fillna """ @@ -943,28 +950,28 @@ def test_fillna_datetime64tz(self, index_or_series, fill_val, fill_dtype): self._assert_fillna_conversion(obj, fill_val, exp, fill_dtype) def test_fillna_series_int64(self): - pass + pytest.xfail("Test not implemented") def test_fillna_index_int64(self): - pass + pytest.xfail("Test not implemented") def test_fillna_series_bool(self): - pass + pytest.xfail("Test not implemented") def test_fillna_index_bool(self): - pass + pytest.xfail("Test not implemented") def test_fillna_series_timedelta64(self): - pass + pytest.xfail("Test not implemented") def test_fillna_series_period(self): - pass + pytest.xfail("Test not implemented") def test_fillna_index_timedelta64(self): - pass + pytest.xfail("Test not implemented") def test_fillna_index_period(self): - pass + pytest.xfail("Test not implemented") class TestReplaceSeriesCoercion(CoercionBase): @@ -1121,4 +1128,4 @@ def test_replace_series_datetime_datetime(self, how, to_key, from_key): tm.assert_series_equal(result, exp) def test_replace_series_period(self): - pass + pytest.xfail("Test not implemented") From 3c703829f0e5847f8edfc2f7cff510f254d4107e Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 28 Apr 2020 18:29:42 -0700 Subject: [PATCH 2/2] REF: collect DTI/TDI/PI tests --- .../tests/indexes/datetimes/test_datetime.py | 72 +------------------ .../tests/indexes/datetimes/test_indexing.py | 15 ++++ pandas/tests/indexes/datetimes/test_map.py | 41 +++++++++++ pandas/tests/indexes/datetimes/test_ops.py | 22 ------ pandas/tests/indexes/datetimes/test_pickle.py | 41 +++++++++++ pandas/tests/indexes/period/test_factorize.py | 37 ++++++++++ pandas/tests/indexes/period/test_indexing.py | 21 ++++++ pandas/tests/indexes/period/test_period.py | 52 -------------- .../indexes/timedeltas/test_searchsorted.py | 26 +++++++ .../indexes/timedeltas/test_timedelta.py | 21 ------ pandas/tests/scalar/test_nat.py | 6 ++ 11 files changed, 188 insertions(+), 166 deletions(-) create mode 100644 pandas/tests/indexes/datetimes/test_map.py create mode 100644 pandas/tests/indexes/datetimes/test_pickle.py create mode 100644 pandas/tests/indexes/period/test_factorize.py create mode 100644 pandas/tests/indexes/timedeltas/test_searchsorted.py diff --git a/pandas/tests/indexes/datetimes/test_datetime.py b/pandas/tests/indexes/datetimes/test_datetime.py index e0e5beaf48e20..50983dbd8db22 100644 --- a/pandas/tests/indexes/datetimes/test_datetime.py +++ b/pandas/tests/indexes/datetimes/test_datetime.py @@ -5,46 +5,13 @@ import pytest import pandas as pd -from pandas import DataFrame, DatetimeIndex, Index, NaT, Timestamp, date_range, offsets +from pandas import DataFrame, DatetimeIndex, Index, Timestamp, date_range, offsets import pandas._testing as tm randn = np.random.randn class TestDatetimeIndex: - def test_roundtrip_pickle_with_tz(self): - - # GH 8367 - # round-trip of timezone - index = date_range("20130101", periods=3, tz="US/Eastern", name="foo") - unpickled = tm.round_trip_pickle(index) - tm.assert_index_equal(index, unpickled) - - def test_pickle(self): - - # GH#4606 - p = tm.round_trip_pickle(NaT) - assert p is NaT - - idx = pd.to_datetime(["2013-01-01", NaT, "2014-01-06"]) - idx_p = tm.round_trip_pickle(idx) - assert idx_p[0] == idx[0] - assert idx_p[1] is NaT - assert idx_p[2] == idx[2] - - # GH#11002 - # don't infer freq - idx = date_range("1750-1-1", "2050-1-1", freq="7D") - idx_p = tm.round_trip_pickle(idx) - tm.assert_index_equal(idx, idx_p) - - def test_pickle_after_set_freq(self): - dti = date_range("20130101", periods=3, tz="US/Eastern", name="foo") - dti = dti._with_freq(None) - - res = tm.round_trip_pickle(dti) - tm.assert_index_equal(res, dti) - def test_reindex_preserves_tz_if_target_is_empty_list_or_array(self): # GH7774 index = date_range("20130101", periods=3, tz="US/Eastern") @@ -164,23 +131,6 @@ def test_append_nondatetimeindex(self): result = rng.append(idx) assert isinstance(result[0], Timestamp) - def test_map(self): - rng = date_range("1/1/2000", periods=10) - - f = lambda x: x.strftime("%Y%m%d") - result = rng.map(f) - exp = Index([f(x) for x in rng], dtype="