From 63abad5bf381ae12e0fc06cb1a7e44b43a534656 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Mon, 13 Aug 2018 23:58:46 +0100 Subject: [PATCH 1/5] Parameterize test case --- .../tests/scalar/timestamp/test_unary_ops.py | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index 9f000a6f22cd6..356f62973f361 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -19,26 +19,16 @@ class TestTimestampUnaryOps(object): # -------------------------------------------------------------- # Timestamp.round - - def test_round_day_naive(self): - dt = Timestamp('20130101 09:10:11') - result = dt.round('D') - expected = Timestamp('20130101') - assert result == expected - - dt = Timestamp('20130101 19:10:11') - result = dt.round('D') - expected = Timestamp('20130102') - assert result == expected - - dt = Timestamp('20130201 12:00:00') - result = dt.round('D') - expected = Timestamp('20130202') - assert result == expected - - dt = Timestamp('20130104 12:00:00') - result = dt.round('D') - expected = Timestamp('20130105') + @pytest.mark.parametrize('timestamp_input, round_freq, date', [ + ('20130101 09:10:11', 'D', '20130101'), + ('20130101 19:10:11', 'D', '20130102'), + ('20130201 12:00:00', 'D', '20130202'), + ('20130104 12:00:00', 'D', '20130105'), + ]) + def test_round_day_naive(self, timestamp_input, round_freq, date): + dt = Timestamp(timestamp_input) + result = dt.round(round_freq) + expected = Timestamp(date) assert result == expected def test_round_tzaware(self): @@ -285,4 +275,4 @@ def test_timestamp(self): with tm.set_timezone('UTC'): # should agree with datetime.timestamp method dt = ts.to_pydatetime() - assert dt.timestamp() == ts.timestamp() + assert dt.timestamp() == ts.timestamp() \ No newline at end of file From ea6f018e81162243ca842c86fd42137054782060 Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Tue, 14 Aug 2018 00:05:38 +0100 Subject: [PATCH 2/5] flake8 add new line --- pandas/tests/scalar/timestamp/test_unary_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index 356f62973f361..4f4d32afbc45b 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -275,4 +275,4 @@ def test_timestamp(self): with tm.set_timezone('UTC'): # should agree with datetime.timestamp method dt = ts.to_pydatetime() - assert dt.timestamp() == ts.timestamp() \ No newline at end of file + assert dt.timestamp() == ts.timestamp() From cfff07c325879c1cee4a372a03f3f411d82d615e Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Tue, 14 Aug 2018 00:34:01 +0100 Subject: [PATCH 3/5] Combine similar test functions --- pandas/tests/scalar/timestamp/test_unary_ops.py | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index 4f4d32afbc45b..1134c1d78e19a 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -24,8 +24,11 @@ class TestTimestampUnaryOps(object): ('20130101 19:10:11', 'D', '20130102'), ('20130201 12:00:00', 'D', '20130202'), ('20130104 12:00:00', 'D', '20130105'), + ('2000-01-05 05:09:15.13', 'D', '2000-01-05 00:00:00'), + ('2000-01-05 05:09:15.13', 'H', '2000-01-05 05:00:00'), + ('2000-01-05 05:09:15.13', 'S', '2000-01-05 05:09:15') ]) - def test_round_day_naive(self, timestamp_input, round_freq, date): + def test_test_round_frequencies(self, timestamp_input, round_freq, date): dt = Timestamp(timestamp_input) result = dt.round(round_freq) expected = Timestamp(date) @@ -75,16 +78,6 @@ def test_round_invalid_arg(self): with tm.assert_raises_regex(ValueError, INVALID_FREQ_ERR_MSG): stamp.round('foo') - @pytest.mark.parametrize('freq, expected', [ - ('D', Timestamp('2000-01-05 00:00:00')), - ('H', Timestamp('2000-01-05 05:00:00')), - ('S', Timestamp('2000-01-05 05:09:15'))]) - def test_round_frequencies(self, freq, expected): - stamp = Timestamp('2000-01-05 05:09:15.13') - - result = stamp.round(freq=freq) - assert result == expected - @pytest.mark.parametrize('test_input, rounder, freq, expected', [ ('2117-01-01 00:00:45', 'floor', '15s', '2117-01-01 00:00:45'), ('2117-01-01 00:00:45', 'ceil', '15s', '2117-01-01 00:00:45'), From cde25005210ce49447e007124c072d519bcd37ef Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Tue, 14 Aug 2018 00:49:44 +0100 Subject: [PATCH 4/5] Fix test name typo --- pandas/tests/scalar/timestamp/test_unary_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index 1134c1d78e19a..fe7d0aa769eee 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -28,7 +28,7 @@ class TestTimestampUnaryOps(object): ('2000-01-05 05:09:15.13', 'H', '2000-01-05 05:00:00'), ('2000-01-05 05:09:15.13', 'S', '2000-01-05 05:09:15') ]) - def test_test_round_frequencies(self, timestamp_input, round_freq, date): + def test_round_frequencies(self, timestamp_input, round_freq, date): dt = Timestamp(timestamp_input) result = dt.round(round_freq) expected = Timestamp(date) From b78995cf29d1e28c20b14d107296e8c9fe0cfddd Mon Sep 17 00:00:00 2001 From: alimcmaster1 Date: Tue, 14 Aug 2018 01:02:27 +0100 Subject: [PATCH 5/5] Update arg names --- pandas/tests/scalar/timestamp/test_unary_ops.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/scalar/timestamp/test_unary_ops.py b/pandas/tests/scalar/timestamp/test_unary_ops.py index fe7d0aa769eee..bf41840c58ded 100644 --- a/pandas/tests/scalar/timestamp/test_unary_ops.py +++ b/pandas/tests/scalar/timestamp/test_unary_ops.py @@ -19,7 +19,7 @@ class TestTimestampUnaryOps(object): # -------------------------------------------------------------- # Timestamp.round - @pytest.mark.parametrize('timestamp_input, round_freq, date', [ + @pytest.mark.parametrize('timestamp, freq, expected', [ ('20130101 09:10:11', 'D', '20130101'), ('20130101 19:10:11', 'D', '20130102'), ('20130201 12:00:00', 'D', '20130202'), @@ -28,10 +28,10 @@ class TestTimestampUnaryOps(object): ('2000-01-05 05:09:15.13', 'H', '2000-01-05 05:00:00'), ('2000-01-05 05:09:15.13', 'S', '2000-01-05 05:09:15') ]) - def test_round_frequencies(self, timestamp_input, round_freq, date): - dt = Timestamp(timestamp_input) - result = dt.round(round_freq) - expected = Timestamp(date) + def test_round_frequencies(self, timestamp, freq, expected): + dt = Timestamp(timestamp) + result = dt.round(freq) + expected = Timestamp(expected) assert result == expected def test_round_tzaware(self):