From 10f7396f386d6b636d709a30a0779dcacb123c9f Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 21 Jan 2020 15:06:31 -0800 Subject: [PATCH 1/4] move misplaced DTI.snap test --- pandas/tests/indexes/datetimes/test_snap.py | 37 +++++++++++++++++++ pandas/tests/series/indexing/test_datetime.py | 33 ----------------- 2 files changed, 37 insertions(+), 33 deletions(-) create mode 100644 pandas/tests/indexes/datetimes/test_snap.py diff --git a/pandas/tests/indexes/datetimes/test_snap.py b/pandas/tests/indexes/datetimes/test_snap.py new file mode 100644 index 0000000000000..a21d27d23f6b5 --- /dev/null +++ b/pandas/tests/indexes/datetimes/test_snap.py @@ -0,0 +1,37 @@ +import pytest + +from pandas import DatetimeIndex, date_range +import pandas._testing as tm + + +@pytest.mark.filterwarnings("ignore::DeprecationWarning") +@pytest.mark.parametrize("tz", [None, "Asia/Shanghai", "Europe/Berlin"]) +@pytest.mark.parametrize("name", [None, "my_dti"]) +def test_dti_snap(name, tz): + dti = DatetimeIndex( + [ + "1/1/2002", + "1/2/2002", + "1/3/2002", + "1/4/2002", + "1/5/2002", + "1/6/2002", + "1/7/2002", + ], + name=name, + tz=tz, + freq="D", + ) + + result = dti.snap(freq="W-MON") + expected = date_range("12/31/2001", "1/7/2002", name=name, tz=tz, freq="w-mon") + expected = expected.repeat([3, 4]) + tm.assert_index_equal(result, expected) + assert result.tz == expected.tz + + result = dti.snap(freq="B") + + expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b") + expected = expected.repeat([1, 1, 1, 2, 2]) + tm.assert_index_equal(result, expected) + assert result.tz == expected.tz diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index 15ff5f6b343d1..a816e9c911d36 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -49,39 +49,6 @@ def test_fancy_setitem(): assert (s[48:54] == -3).all() -@pytest.mark.filterwarnings("ignore::DeprecationWarning") -@pytest.mark.parametrize("tz", [None, "Asia/Shanghai", "Europe/Berlin"]) -@pytest.mark.parametrize("name", [None, "my_dti"]) -def test_dti_snap(name, tz): - dti = DatetimeIndex( - [ - "1/1/2002", - "1/2/2002", - "1/3/2002", - "1/4/2002", - "1/5/2002", - "1/6/2002", - "1/7/2002", - ], - name=name, - tz=tz, - freq="D", - ) - - result = dti.snap(freq="W-MON") - expected = date_range("12/31/2001", "1/7/2002", name=name, tz=tz, freq="w-mon") - expected = expected.repeat([3, 4]) - tm.assert_index_equal(result, expected) - assert result.tz == expected.tz - - result = dti.snap(freq="B") - - expected = date_range("1/1/2002", "1/7/2002", name=name, tz=tz, freq="b") - expected = expected.repeat([1, 1, 1, 2, 2]) - tm.assert_index_equal(result, expected) - assert result.tz == expected.tz - - def test_dti_reset_index_round_trip(): dti = date_range(start="1/1/2001", end="6/1/2001", freq="D") d1 = DataFrame({"v": np.random.rand(len(dti))}, index=dti) From 7aef0d336eec81be31e214fa6a88901c83a46018 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 21 Jan 2020 15:16:13 -0800 Subject: [PATCH 2/4] move misplaced round test --- pandas/tests/series/indexing/test_datetime.py | 10 ---------- pandas/tests/series/methods/test_round.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pandas/tests/series/indexing/test_datetime.py b/pandas/tests/series/indexing/test_datetime.py index a816e9c911d36..77085ef547690 100644 --- a/pandas/tests/series/indexing/test_datetime.py +++ b/pandas/tests/series/indexing/test_datetime.py @@ -718,16 +718,6 @@ def test_nat_operations(): assert s.max() == exp -@pytest.mark.parametrize("method", ["round", "floor", "ceil"]) -@pytest.mark.parametrize("freq", ["s", "5s", "min", "5min", "h", "5h"]) -def test_round_nat(method, freq): - # GH14940 - s = Series([pd.NaT]) - expected = Series(pd.NaT) - round_method = getattr(s.dt, method) - tm.assert_series_equal(round_method(freq), expected) - - def test_setitem_tuple_with_datetimetz(): # GH 20441 arr = date_range("2017", periods=4, tz="US/Eastern") diff --git a/pandas/tests/series/methods/test_round.py b/pandas/tests/series/methods/test_round.py index 7f0711a0f30d7..88d5c428712dc 100644 --- a/pandas/tests/series/methods/test_round.py +++ b/pandas/tests/series/methods/test_round.py @@ -1,6 +1,7 @@ import numpy as np import pytest +import pandas as pd from pandas import Series import pandas._testing as tm @@ -44,3 +45,12 @@ def test_round_builtin(self): expected_rounded = Series([1.12, 2.12, 3.12], index=range(3)) result = round(ser, decimals) tm.assert_series_equal(result, expected_rounded) + + @pytest.mark.parametrize("method", ["round", "floor", "ceil"]) + @pytest.mark.parametrize("freq", ["s", "5s", "min", "5min", "h", "5h"]) + def test_round_nat(self, method, freq): + # GH14940 + ser = Series([pd.NaT]) + expected = Series(pd.NaT) + round_method = getattr(ser.dt, method) + tm.assert_series_equal(round_method(freq), expected) From c5c9fbfffdac0a3dc5bc588a8c2d66d72480d6cf Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 21 Jan 2020 15:19:02 -0800 Subject: [PATCH 3/4] move misplaced MultiIndex set test --- pandas/tests/indexes/multi/test_setops.py | 11 +++++++++++ pandas/tests/indexing/multiindex/test_set_ops.py | 12 +----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pandas/tests/indexes/multi/test_setops.py b/pandas/tests/indexes/multi/test_setops.py index 841e3b3f17b38..f949db537de67 100644 --- a/pandas/tests/indexes/multi/test_setops.py +++ b/pandas/tests/indexes/multi/test_setops.py @@ -110,6 +110,17 @@ def test_symmetric_difference(idx, sort): first.symmetric_difference([1, 2, 3], sort=sort) +def test_multiindex_symmetric_difference(): + # GH 13490 + idx = MultiIndex.from_product([["a", "b"], ["A", "B"]], names=["a", "b"]) + result = idx ^ idx + assert result.names == idx.names + + idx2 = idx.copy().rename(["A", "B"]) + result = idx ^ idx2 + assert result.names == [None, None] + + def test_empty(idx): # GH 15270 assert not idx.empty diff --git a/pandas/tests/indexing/multiindex/test_set_ops.py b/pandas/tests/indexing/multiindex/test_set_ops.py index f2cbfadb3cfa5..835e61da2fb3e 100644 --- a/pandas/tests/indexing/multiindex/test_set_ops.py +++ b/pandas/tests/indexing/multiindex/test_set_ops.py @@ -4,17 +4,7 @@ import pandas._testing as tm -class TestMultiIndexSetOps: - def test_multiindex_symmetric_difference(self): - # GH 13490 - idx = MultiIndex.from_product([["a", "b"], ["A", "B"]], names=["a", "b"]) - result = idx ^ idx - assert result.names == idx.names - - idx2 = idx.copy().rename(["A", "B"]) - result = idx ^ idx2 - assert result.names == [None, None] - +class TestMultiIndexInsertion: def test_mixed_depth_insert(self): arrays = [ ["a", "top", "top", "routine1", "routine1", "routine2"], From b82713b4eaafccca6af4490c53981859d68871ea Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Tue, 21 Jan 2020 15:19:42 -0800 Subject: [PATCH 4/4] rename --- .../tests/indexing/multiindex/{test_set_ops.py => test_insert.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pandas/tests/indexing/multiindex/{test_set_ops.py => test_insert.py} (100%) diff --git a/pandas/tests/indexing/multiindex/test_set_ops.py b/pandas/tests/indexing/multiindex/test_insert.py similarity index 100% rename from pandas/tests/indexing/multiindex/test_set_ops.py rename to pandas/tests/indexing/multiindex/test_insert.py