From 781994f806ca0ca2464e88ac702f6f097e56d2de Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 12:50:51 +0100 Subject: [PATCH 1/9] BUG: caught typeError in series.at (#25506) --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index cada6663ce651..3d275edc2f78b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1229,7 +1229,7 @@ def _set_value(self, label, value, takeable=False): self._values[label] = value else: self.index._engine.set_value(self._values, label, value) - except KeyError: + except (KeyError, TypeError): # set using a non-recursive method self.loc[label] = value From 24ebb20a89532e06eacf404d4d84d6ddb27d978d Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 13:44:43 +0100 Subject: [PATCH 2/9] =?UTF-8?q?Added=20what=E2=80=99s=20new=20entry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 124ec8f4ab92c..a488a17ef7bbd 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -150,7 +150,7 @@ Timezones - Bug in :func:`to_datetime` with ``utc=True`` and datetime strings that would apply previously parsed UTC offsets to subsequent arguments (:issue:`24992`) - Bug in :func:`Timestamp.tz_localize` and :func:`Timestamp.tz_convert` does not propagate ``freq`` (:issue:`25241`) -- +- Bug in :func:`series.at` where Setting Timestamp with timezone raises TypeError (:issue:`25506`) Numeric ^^^^^^^ From f31715adff9d3879308b3802a178df4f38a8e9e6 Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 17:32:15 +0100 Subject: [PATCH 3/9] =?UTF-8?q?Updated=20what=E2=80=99s=20new=20message=20?= =?UTF-8?q?according=20to=20convention?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index a488a17ef7bbd..fd73bb488d673 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -150,7 +150,7 @@ Timezones - Bug in :func:`to_datetime` with ``utc=True`` and datetime strings that would apply previously parsed UTC offsets to subsequent arguments (:issue:`24992`) - Bug in :func:`Timestamp.tz_localize` and :func:`Timestamp.tz_convert` does not propagate ``freq`` (:issue:`25241`) -- Bug in :func:`series.at` where Setting Timestamp with timezone raises TypeError (:issue:`25506`) +- Bug in :func:`Series.at` where Setting :class:`Timestamp` with timezone raises ``TypeError`` (:issue:`25506`) Numeric ^^^^^^^ From a218db743391970f0048f588d7736f9a2ecea4be Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 18:27:40 +0100 Subject: [PATCH 4/9] Added a test to verify the bug was fixed --- pandas/tests/series/test_timezones.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/series/test_timezones.py b/pandas/tests/series/test_timezones.py index ec644a8e93da2..df41277ba35e7 100644 --- a/pandas/tests/series/test_timezones.py +++ b/pandas/tests/series/test_timezones.py @@ -364,3 +364,13 @@ def test_tz_localize_convert_copy_inplace_mutate(self, copy, method, tz): index=date_range('20131027', periods=5, freq='1H', tz=tz)) tm.assert_series_equal(result, expected) + + def test_series_set_tz_timestamp(self): + # GH 25506 + ts = Timestamp('2017-08-05 00:00:00+0100', tz=pytz.FixedOffset(60)) + result = Series(ts) + result.at[1] = ts + expected = Series([ts, ts]) + tm.assert_series_equal(result, expected) + + From a8c8fde7e34acea2858133741e8338c7b48e3c6b Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 18:29:58 +0100 Subject: [PATCH 5/9] Fix PEP8 violation: blank line at end of file --- pandas/tests/series/test_timezones.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/series/test_timezones.py b/pandas/tests/series/test_timezones.py index df41277ba35e7..59a78a70755ab 100644 --- a/pandas/tests/series/test_timezones.py +++ b/pandas/tests/series/test_timezones.py @@ -372,5 +372,3 @@ def test_series_set_tz_timestamp(self): result.at[1] = ts expected = Series([ts, ts]) tm.assert_series_equal(result, expected) - - From 299a5e2bb97307f20585103eceb23e2cbe155009 Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 18:42:11 +0100 Subject: [PATCH 6/9] Fixed capitalisation of setting --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index fd73bb488d673..e1a1c975b5ed8 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -150,7 +150,7 @@ Timezones - Bug in :func:`to_datetime` with ``utc=True`` and datetime strings that would apply previously parsed UTC offsets to subsequent arguments (:issue:`24992`) - Bug in :func:`Timestamp.tz_localize` and :func:`Timestamp.tz_convert` does not propagate ``freq`` (:issue:`25241`) -- Bug in :func:`Series.at` where Setting :class:`Timestamp` with timezone raises ``TypeError`` (:issue:`25506`) +- Bug in :func:`Series.at` where setting :class:`Timestamp` with timezone raises ``TypeError`` (:issue:`25506`) Numeric ^^^^^^^ From e494592024940331058197533c69e720ef2f0338 Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 20:27:54 +0100 Subject: [PATCH 7/9] Used tz_naive_fixture and moved to test_scalar.py --- pandas/tests/indexing/test_scalar.py | 12 ++++++++++++ pandas/tests/series/test_timezones.py | 8 -------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pandas/tests/indexing/test_scalar.py b/pandas/tests/indexing/test_scalar.py index 0cd41562541d1..da49dfc69d34d 100644 --- a/pandas/tests/indexing/test_scalar.py +++ b/pandas/tests/indexing/test_scalar.py @@ -2,6 +2,7 @@ import numpy as np import pytest +from pytz import FixedOffset from pandas import DataFrame, Series, Timedelta, Timestamp, date_range from pandas.tests.indexing.common import Base @@ -185,6 +186,17 @@ def test_at_with_tz(self): result = df.at[0, 'date'] assert result == expected + @pytest.mark.parametrize('tz', [ + None, 'UTC', 'US/Eastern', 'Asia/Tokyo', + 'dateutil/US/Pacific', 'CET', FixedOffset(60)]) + def test_series_set_tz_timestamp(self, tz): + # GH 25506 + ts = Timestamp('2017-08-05 00:00:00+0100', tz=tz) + result = Series(ts) + result.at[1] = ts + expected = Series([ts, ts]) + tm.assert_series_equal(result, expected) + def test_mixed_index_at_iat_loc_iloc_series(self): # GH 19860 s = Series([1, 2, 3, 4, 5], index=['a', 'b', 'c', 1, 2]) diff --git a/pandas/tests/series/test_timezones.py b/pandas/tests/series/test_timezones.py index 59a78a70755ab..ec644a8e93da2 100644 --- a/pandas/tests/series/test_timezones.py +++ b/pandas/tests/series/test_timezones.py @@ -364,11 +364,3 @@ def test_tz_localize_convert_copy_inplace_mutate(self, copy, method, tz): index=date_range('20131027', periods=5, freq='1H', tz=tz)) tm.assert_series_equal(result, expected) - - def test_series_set_tz_timestamp(self): - # GH 25506 - ts = Timestamp('2017-08-05 00:00:00+0100', tz=pytz.FixedOffset(60)) - result = Series(ts) - result.at[1] = ts - expected = Series([ts, ts]) - tm.assert_series_equal(result, expected) From 2c071088da1e0ba2753df039fbffcca4aaf55872 Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 20:33:01 +0100 Subject: [PATCH 8/9] Used tz_naive_fixture correctly --- pandas/tests/indexing/test_scalar.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/tests/indexing/test_scalar.py b/pandas/tests/indexing/test_scalar.py index da49dfc69d34d..16c6a65d1c293 100644 --- a/pandas/tests/indexing/test_scalar.py +++ b/pandas/tests/indexing/test_scalar.py @@ -186,12 +186,9 @@ def test_at_with_tz(self): result = df.at[0, 'date'] assert result == expected - @pytest.mark.parametrize('tz', [ - None, 'UTC', 'US/Eastern', 'Asia/Tokyo', - 'dateutil/US/Pacific', 'CET', FixedOffset(60)]) - def test_series_set_tz_timestamp(self, tz): + def test_series_set_tz_timestamp(self, tz_naive_fixture): # GH 25506 - ts = Timestamp('2017-08-05 00:00:00+0100', tz=tz) + ts = Timestamp('2017-08-05 00:00:00+0100', tz=tz_naive_fixture) result = Series(ts) result.at[1] = ts expected = Series([ts, ts]) From ceb13f87772878d822c21597cadcf7dc69a22de3 Mon Sep 17 00:00:00 2001 From: jopenmolles Date: Mon, 4 Mar 2019 21:06:16 +0100 Subject: [PATCH 9/9] Removed unused import --- pandas/tests/indexing/test_scalar.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/indexing/test_scalar.py b/pandas/tests/indexing/test_scalar.py index 16c6a65d1c293..20053264ac4f1 100644 --- a/pandas/tests/indexing/test_scalar.py +++ b/pandas/tests/indexing/test_scalar.py @@ -2,7 +2,6 @@ import numpy as np import pytest -from pytz import FixedOffset from pandas import DataFrame, Series, Timedelta, Timestamp, date_range from pandas.tests.indexing.common import Base