From c092f2c9815ade05fba27ad24040a1d40d972dad Mon Sep 17 00:00:00 2001 From: marlene Date: Sat, 4 Aug 2018 21:18:05 +0200 Subject: [PATCH 1/4] Fix GH21194, implementing parametrizing tests --- doc/source/whatsnew/v0.23.1.txt | 1 + pandas/core/indexes/base.py | 2 +- pandas/tests/frame/test_asof.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index 1a514ba627fcb..e953cfeaff46b 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -138,3 +138,4 @@ Bug Fixes - Tab completion on :class:`Index` in IPython no longer outputs deprecation warnings (:issue:`21125`) - Bug preventing pandas being used on Windows without C++ redistributable installed (:issue:`21106`) +- Bug in :func:`Dataframe.asof` that raised a ``TypeError`` when attempting to compare tz-naive and tz-aware timestamps (:issue:`21194`) \ No newline at end of file diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 2a191ef76473b..5a4e89adb2737 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2463,7 +2463,7 @@ def asof_locs(self, where, mask): result = np.arange(len(self))[mask].take(locs) first = mask.argmax() - result[(locs == 0) & (where < self.values[first])] = -1 + result[(locs == 0) & (where.values < self.values[first])] = -1 return result diff --git a/pandas/tests/frame/test_asof.py b/pandas/tests/frame/test_asof.py index fea6a5370109e..93cc0354ea461 100644 --- a/pandas/tests/frame/test_asof.py +++ b/pandas/tests/frame/test_asof.py @@ -1,6 +1,7 @@ # coding=utf-8 import numpy as np +import pytest from pandas import (DataFrame, date_range, Timestamp, Series, to_datetime) @@ -106,3 +107,21 @@ def test_all_nans(self): result = DataFrame(np.nan, index=[1, 2], columns=['A', 'B']).asof(3) expected = Series(np.nan, index=['A', 'B'], name=3) tm.assert_series_equal(result, expected) + + # Testing awareness of DataFrame index considering different + # UTC and timezone + @pytest.mark.parametrize( + "stamp,expected", + [(Timestamp('2018-01-01 23:22:43.325+00:00'), + Series(2.0, name=Timestamp('2018-01-01 23:22:43.325+00:00'))), + (Timestamp('2018-01-01 22:33:20.682+01:00'), + Series(1.0, name=Timestamp('2018-01-01 22:33:20.682+01:00'))), + ] + ) + def test_time_zone_aware_index(self, stamp, expected): + # GH21194 + df = DataFrame(data=[1, 2], + index=[Timestamp('2018-01-01 21:00:05.001+00:00'), + Timestamp('2018-01-01 22:35:10.550+00:00')]) + result = df.asof(stamp) + tm.assert_series_equal(result, expected) From 25060af70ef92a3adee21a95dbf4c19d71af9f52 Mon Sep 17 00:00:00 2001 From: marlene Date: Sun, 5 Aug 2018 13:55:26 +0200 Subject: [PATCH 2/4] Editing whatsnew v0.23.1 and v0.24.0 --- doc/source/whatsnew/v0.23.1.txt | 3 +-- doc/source/whatsnew/v0.24.0.txt | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index e953cfeaff46b..80ddeaef42e44 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -137,5 +137,4 @@ Bug Fixes **Other** - Tab completion on :class:`Index` in IPython no longer outputs deprecation warnings (:issue:`21125`) -- Bug preventing pandas being used on Windows without C++ redistributable installed (:issue:`21106`) -- Bug in :func:`Dataframe.asof` that raised a ``TypeError`` when attempting to compare tz-naive and tz-aware timestamps (:issue:`21194`) \ No newline at end of file +- Bug preventing pandas being used on Windows without C++ redistributable installed (:issue:`21106`) \ No newline at end of file diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 5c15c7b6a742f..842e999705eae 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -561,6 +561,7 @@ Timezones - Fixed bug where :meth:`DataFrame.describe` and :meth:`Series.describe` on tz-aware datetimes did not show `first` and `last` result (:issue:`21328`) - Bug in :class:`DatetimeIndex` comparisons failing to raise ``TypeError`` when comparing timezone-aware ``DatetimeIndex`` against ``np.datetime64`` (:issue:`22074`) - Bug in ``DataFrame`` assignment with a timezone-aware scalar (:issue:`19843`) +- Bug in :func:`Dataframe.asof` that raised a ``TypeError`` when attempting to compare tz-naive and tz-aware timestamps (:issue:`21194`) Offsets ^^^^^^^ From 964a0d8b80724be2701ae0c1176ef02b75342463 Mon Sep 17 00:00:00 2001 From: marlene Date: Sun, 5 Aug 2018 14:11:57 +0200 Subject: [PATCH 3/4] Solving diff in v0.23.1 --- doc/source/whatsnew/v0.23.1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.23.1.txt b/doc/source/whatsnew/v0.23.1.txt index 80ddeaef42e44..1a514ba627fcb 100644 --- a/doc/source/whatsnew/v0.23.1.txt +++ b/doc/source/whatsnew/v0.23.1.txt @@ -137,4 +137,4 @@ Bug Fixes **Other** - Tab completion on :class:`Index` in IPython no longer outputs deprecation warnings (:issue:`21125`) -- Bug preventing pandas being used on Windows without C++ redistributable installed (:issue:`21106`) \ No newline at end of file +- Bug preventing pandas being used on Windows without C++ redistributable installed (:issue:`21106`) From b9259b8561933530b1e56b11897a9edf7a43a11a Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Mon, 6 Aug 2018 06:32:16 -0400 Subject: [PATCH 4/4] rebase --- pandas/tests/frame/test_asof.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/test_asof.py b/pandas/tests/frame/test_asof.py index 93cc0354ea461..091a5fb14e65e 100644 --- a/pandas/tests/frame/test_asof.py +++ b/pandas/tests/frame/test_asof.py @@ -108,8 +108,6 @@ def test_all_nans(self): expected = Series(np.nan, index=['A', 'B'], name=3) tm.assert_series_equal(result, expected) - # Testing awareness of DataFrame index considering different - # UTC and timezone @pytest.mark.parametrize( "stamp,expected", [(Timestamp('2018-01-01 23:22:43.325+00:00'), @@ -120,6 +118,8 @@ def test_all_nans(self): ) def test_time_zone_aware_index(self, stamp, expected): # GH21194 + # Testing awareness of DataFrame index considering different + # UTC and timezone df = DataFrame(data=[1, 2], index=[Timestamp('2018-01-01 21:00:05.001+00:00'), Timestamp('2018-01-01 22:35:10.550+00:00')])