From 8be97f8f3ce2db4ed85db2c6c68d8c39508df3a6 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 5 Aug 2019 14:34:23 +0200 Subject: [PATCH 01/51] Fix numpy boolean subtraction error in Series.diff Numpy no longer allows subtraction of boolean values. Not sure if Numpy version checking should be done before this code... Note: I haven't actually run this code, feel free to check it, but should be correct. --------------------------------------------------------------------------- TypeError Traceback (most recent call last) in 1 data = pd.Series([0,-1,-2,-3,-4,-3,-2,-1,0,-1,-1,0,-1,-2,-3,-2,0]) 2 filtered = data.between(-2,0, inclusive = True) ----> 3 filtered.diff() 4 print(filtered) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\series.py in diff(self, periods) 2191 dtype: float64 2192 """ -> 2193 result = algorithms.diff(com.values_from_object(self), periods) 2194 return self._constructor(result, index=self.index).__finalize__(self) 2195 ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\algorithms.py in diff(arr, n, axis) 1817 out_arr[res_indexer] = result 1818 else: -> 1819 out_arr[res_indexer] = arr[res_indexer] - arr[lag_indexer] 1820 1821 if is_timedelta: TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the bitwise_xor, the `^` operator, or the logical_xor function instead. --- pandas/core/algorithms.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 21d12d02c9008..70971a5f8aef7 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1933,6 +1933,7 @@ def diff(arr, n, axis=0): elif is_bool_dtype(dtype): dtype = np.object_ + is_bool = True elif is_integer_dtype(dtype): dtype = np.float64 @@ -1972,6 +1973,8 @@ def diff(arr, n, axis=0): result = res - lag result[mask] = na out_arr[res_indexer] = result + elif is_bool: + out_arr[res_indexer] = arr[res_indexer] ^ arr[lag_indexer] else: out_arr[res_indexer] = arr[res_indexer] - arr[lag_indexer] From 7c982d20a2fc61a472aa1be134aa69e04a2537a9 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 5 Aug 2019 15:18:53 +0200 Subject: [PATCH 02/51] Added is_bool outside if function --- pandas/core/algorithms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 70971a5f8aef7..6e1c2f1c178b8 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1925,6 +1925,7 @@ def diff(arr, n, axis=0): dtype = arr.dtype is_timedelta = False + is_bool = False if needs_i8_conversion(arr): dtype = np.float64 arr = arr.view("i8") From 45f9c60fd0eb069d54b0ee7e6845d91a91baf6fe Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 5 Aug 2019 15:56:45 +0200 Subject: [PATCH 03/51] Added test_diff function --- pandas/tests/series/test_diff.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pandas/tests/series/test_diff.py diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py new file mode 100644 index 0000000000000..d6c443d2c5b62 --- /dev/null +++ b/pandas/tests/series/test_diff.py @@ -0,0 +1,17 @@ +from pandas import ( + Series +) + +from numpy import nan + +def test_diff(): + data = Series([0,-1,-2,-3,-4,-3,-2,-1,0,-1,-1,0,-1,-2,-3,-2,0]) + + filtered = data.between(-2,0, inclusive = True) + diff_boolean = filtered.diff() + expected_boolean = Series([nan, False, False, True, False, False, True, False, False, False, False, False, False, False, True, True, False]) + assert diff_boolean.equals(expected_boolean) + + diff_data = data.diff() + expected_data = Series([nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 2.0]) + assert diff_data.equals(expected_data) From 83907a2f1cb5ec2a4e04f22196af7b5fe41e6f22 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 5 Aug 2019 15:58:40 +0200 Subject: [PATCH 04/51] Update test_diff.py --- pandas/tests/series/test_diff.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index d6c443d2c5b62..404688b673de6 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -6,12 +6,10 @@ def test_diff(): data = Series([0,-1,-2,-3,-4,-3,-2,-1,0,-1,-1,0,-1,-2,-3,-2,0]) - filtered = data.between(-2,0, inclusive = True) diff_boolean = filtered.diff() expected_boolean = Series([nan, False, False, True, False, False, True, False, False, False, False, False, False, False, True, True, False]) assert diff_boolean.equals(expected_boolean) - diff_data = data.diff() expected_data = Series([nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 2.0]) assert diff_data.equals(expected_data) From 6c3875e5b640e2eee9139737864171bcac7a10b6 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 5 Aug 2019 16:04:56 +0200 Subject: [PATCH 05/51] Changing style to match PEP --- pandas/tests/series/test_diff.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 404688b673de6..8eeed64ec432a 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -4,12 +4,21 @@ from numpy import nan + def test_diff(): - data = Series([0,-1,-2,-3,-4,-3,-2,-1,0,-1,-1,0,-1,-2,-3,-2,0]) - filtered = data.between(-2,0, inclusive = True) + data = Series( + [0, -1, -2, -3, -4, -3, -2, -1, 0, -1, -1, 0, -1, -2, -3, -2, 0] + ) + filtered = data.between(-2, 0, inclusive=True) diff_boolean = filtered.diff() - expected_boolean = Series([nan, False, False, True, False, False, True, False, False, False, False, False, False, False, True, True, False]) + expected_boolean = Series( + [nan, False, False, True, False, False, True, False, False, \ + False, False, False, False, False, True, True, False] + ) assert diff_boolean.equals(expected_boolean) diff_data = data.diff() - expected_data = Series([nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 2.0]) + expected_data = Series( + [nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, \ + -1.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 2.0] + ) assert diff_data.equals(expected_data) From ecf1c04a27e73514ec7e6fc4e6518c6e78a69530 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 5 Aug 2019 16:06:48 +0200 Subject: [PATCH 06/51] Update test_diff.py --- pandas/tests/series/test_diff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 8eeed64ec432a..564f45f4c5bc6 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -12,13 +12,13 @@ def test_diff(): filtered = data.between(-2, 0, inclusive=True) diff_boolean = filtered.diff() expected_boolean = Series( - [nan, False, False, True, False, False, True, False, False, \ + [nan, False, False, True, False, False, True, False, False, False, False, False, False, False, True, True, False] ) assert diff_boolean.equals(expected_boolean) diff_data = data.diff() expected_data = Series( - [nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, \ + [nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 2.0] ) assert diff_data.equals(expected_data) From dd8ff9839fa515b8e04dd56b55ed40081127d62a Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 5 Aug 2019 17:04:48 +0200 Subject: [PATCH 07/51] Using tm to assert series differences --- pandas/tests/series/test_diff.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 564f45f4c5bc6..9f6545c5cecbe 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -1,24 +1,23 @@ -from pandas import ( - Series -) - from numpy import nan +from pandas import Series +import pandas.util.testing as tm def test_diff(): + ''' + Tests the pd.Series diff function on boolean series. + ''' data = Series( - [0, -1, -2, -3, -4, -3, -2, -1, 0, -1, -1, 0, -1, -2, -3, -2, 0] + [0, -1, -2, -3, -4, -3, -2, -1, 0] ) filtered = data.between(-2, 0, inclusive=True) diff_boolean = filtered.diff() expected_boolean = Series( - [nan, False, False, True, False, False, True, False, False, - False, False, False, False, False, True, True, False] + [nan, False, False, True, False, False, True, False, False] ) - assert diff_boolean.equals(expected_boolean) + tm.assert_series_equal(diff_boolean, expected_boolean) diff_data = data.diff() expected_data = Series( - [nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, - -1.0, 0.0, 1.0, -1.0, -1.0, -1.0, 1.0, 2.0] + [nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0] ) - assert diff_data.equals(expected_data) + tm.assert_series_equal(diff_data, expected_data) From e123486314f90a6ef129901114fbeb93283e5233 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 11:21:07 +0200 Subject: [PATCH 08/51] Added diff bug description to changelog --- doc/source/whatsnew/v0.25.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index 4d9ee4c676759..4b0358a893d15 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -153,7 +153,7 @@ ExtensionArray Other ^^^^^ - Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when replacing timezone-aware timestamps using a dict-like replacer (:issue:`27720`) -- +- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 - - From 269d148d2f5d88b04d55badf1b5c41edadd33a58 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 11:31:48 +0200 Subject: [PATCH 09/51] Added issue number --- doc/source/whatsnew/v0.25.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index 4b0358a893d15..181b208d70d49 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -153,7 +153,7 @@ ExtensionArray Other ^^^^^ - Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when replacing timezone-aware timestamps using a dict-like replacer (:issue:`27720`) -- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 +- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 (:issue:`17294`) - - From 3993206038774ae174d1dd7f35fc82df2b8f030e Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 12:15:18 +0200 Subject: [PATCH 10/51] Adding timeseries tests as well --- pandas/tests/series/test_diff.py | 82 +++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 23 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 9f6545c5cecbe..af2d078ed2d0c 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -1,23 +1,59 @@ -from numpy import nan -from pandas import Series -import pandas.util.testing as tm - - -def test_diff(): - ''' - Tests the pd.Series diff function on boolean series. - ''' - data = Series( - [0, -1, -2, -3, -4, -3, -2, -1, 0] - ) - filtered = data.between(-2, 0, inclusive=True) - diff_boolean = filtered.diff() - expected_boolean = Series( - [nan, False, False, True, False, False, True, False, False] - ) - tm.assert_series_equal(diff_boolean, expected_boolean) - diff_data = data.diff() - expected_data = Series( - [nan, -1.0, -1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0] - ) - tm.assert_series_equal(diff_data, expected_data) +from pandas import ( + Series, + date_range, +) +from pandas.tests.series.common import TestData +from pandas.core.indexes.timedeltas import TimedeltaIndex +from pandas.util.testing import assert_series_equal + +class TestDiff(TestData): + def test_diff(self): + # Just run the function + self.ts.diff() + + # int dtype + a = 10000000000000000 + b = a + 1 + s = Series([a, b]) + + rs = s.diff() + assert rs[1] == 1 + + # neg n + rs = self.ts.diff(-1) + xp = self.ts - self.ts.shift(-1) + assert_series_equal(rs, xp) + + # 0 + rs = self.ts.diff(0) + xp = self.ts - self.ts + assert_series_equal(rs, xp) + + # datetime diff (GH3100) + s = Series(date_range("20130102", periods=5)) + rs = s - s.shift(1) + xp = s.diff() + assert_series_equal(rs, xp) + + # timedelta diff + nrs = rs - rs.shift(1) + nxp = xp.diff() + assert_series_equal(nrs, nxp) + + # with tz + s = Series( + date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" + ) + result = s.diff() + assert_series_equal( + result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") + ) + + # boolean series + s = Series( + [False, True, True, False, False] + ) + result = s.diff() + assert_series_equal( + result, Series[nan, True, False, True, False] + ) From b610dd9fec32d88a8653cd7f264c94498de51411 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 12:16:56 +0200 Subject: [PATCH 11/51] Removed test_diff, it is added to test_diff.py I copied the data over to the other file, diff tests should be in one file and the boolean test cannot be added to this one as it is not a time series. --- pandas/tests/series/test_timeseries.py | 42 -------------------------- 1 file changed, 42 deletions(-) diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index d0ca5d82c6b33..fbe3f929cf5b5 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -355,48 +355,6 @@ def test_asfreq_datetimeindex_empty_series(self): ) tm.assert_index_equal(expected.index, result.index) - def test_diff(self): - # Just run the function - self.ts.diff() - - # int dtype - a = 10000000000000000 - b = a + 1 - s = Series([a, b]) - - rs = s.diff() - assert rs[1] == 1 - - # neg n - rs = self.ts.diff(-1) - xp = self.ts - self.ts.shift(-1) - assert_series_equal(rs, xp) - - # 0 - rs = self.ts.diff(0) - xp = self.ts - self.ts - assert_series_equal(rs, xp) - - # datetime diff (GH3100) - s = Series(date_range("20130102", periods=5)) - rs = s - s.shift(1) - xp = s.diff() - assert_series_equal(rs, xp) - - # timedelta diff - nrs = rs - rs.shift(1) - nxp = xp.diff() - assert_series_equal(nrs, nxp) - - # with tz - s = Series( - date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" - ) - result = s.diff() - assert_series_equal( - result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") - ) - def test_pct_change(self): rs = self.ts.pct_change(fill_method=None) assert_series_equal(rs, self.ts / self.ts.shift(1) - 1) From 92075fbc3cec3426c71752d71ab6739e620cae5b Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 13:06:10 +0200 Subject: [PATCH 12/51] Removed too much code, importing nan again --- pandas/tests/series/test_diff.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index af2d078ed2d0c..dc77e15fdbec5 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -1,3 +1,4 @@ +from numpy import nan from pandas import ( Series, date_range, From 1b906575f2606a66e307c5bc99dcbb2de379b23e Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 13:08:38 +0200 Subject: [PATCH 13/51] STYLE: formatting... --- pandas/tests/series/test_diff.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index dc77e15fdbec5..1bb9c57701748 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -1,12 +1,10 @@ from numpy import nan -from pandas import ( - Series, - date_range, -) +from pandas import Series, date_range from pandas.tests.series.common import TestData from pandas.core.indexes.timedeltas import TimedeltaIndex from pandas.util.testing import assert_series_equal + class TestDiff(TestData): def test_diff(self): # Just run the function @@ -51,10 +49,6 @@ def test_diff(self): ) # boolean series - s = Series( - [False, True, True, False, False] - ) + s = Series([False, True, True, False, False]) result = s.diff() - assert_series_equal( - result, Series[nan, True, False, True, False] - ) + assert_series_equal(result, Series[nan, True, False, True, False]) From 182cbc25b5535d65fd7284b95d4f893c6ea36782 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 13:37:34 +0200 Subject: [PATCH 14/51] Splitting into two functions --- pandas/tests/series/test_diff.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 1bb9c57701748..a37f64956f834 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -6,7 +6,7 @@ class TestDiff(TestData): - def test_diff(self): + def test_ts_diff(self): # Just run the function self.ts.diff() @@ -47,7 +47,8 @@ def test_diff(self): assert_series_equal( result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") ) - + + def test_boolean_diff(self): # boolean series s = Series([False, True, True, False, False]) result = s.diff() From 3ba0958f98d15f8bf2a72a94a018400be9b8489b Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 13:48:35 +0200 Subject: [PATCH 15/51] Split into 3 functions --- pandas/tests/series/test_diff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index a37f64956f834..692b0c5ae9c1a 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -27,7 +27,8 @@ def test_ts_diff(self): rs = self.ts.diff(0) xp = self.ts - self.ts assert_series_equal(rs, xp) - + + def test_datetime_diff(self): # datetime diff (GH3100) s = Series(date_range("20130102", periods=5)) rs = s - s.shift(1) From 47feb3056a2d1447d46adcdb82732604d579a414 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 14:34:21 +0200 Subject: [PATCH 16/51] Update test_diff.py --- pandas/tests/series/test_diff.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 692b0c5ae9c1a..a15c72360aada 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -6,7 +6,7 @@ class TestDiff(TestData): - def test_ts_diff(self): + def test_diff(self): # Just run the function self.ts.diff() @@ -28,7 +28,6 @@ def test_ts_diff(self): xp = self.ts - self.ts assert_series_equal(rs, xp) - def test_datetime_diff(self): # datetime diff (GH3100) s = Series(date_range("20130102", periods=5)) rs = s - s.shift(1) @@ -49,7 +48,6 @@ def test_datetime_diff(self): result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") ) - def test_boolean_diff(self): # boolean series s = Series([False, True, True, False, False]) result = s.diff() From d425cdf273d13c53010a8b8ba6194b2d56d4c3b7 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 15:25:20 +0200 Subject: [PATCH 17/51] Adding nan test --- pandas/tests/series/test_diff.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index a15c72360aada..43d7a9d41cf77 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -51,4 +51,9 @@ def test_diff(self): # boolean series s = Series([False, True, True, False, False]) result = s.diff() - assert_series_equal(result, Series[nan, True, False, True, False]) + assert_series_equal(result, Series([nan, True, False, True, False])) + + # boolean nan series + s = Series([False, True, nan, False, False]) + result = s.diff() + assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype = "object")) From 050b8cb424e31fd7118354b033f3c40759999a30 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 16:05:54 +0200 Subject: [PATCH 18/51] STYLE: Black formatting --- pandas/tests/series/test_diff.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 43d7a9d41cf77..7e303be7ee770 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -27,7 +27,7 @@ def test_diff(self): rs = self.ts.diff(0) xp = self.ts - self.ts assert_series_equal(rs, xp) - + # datetime diff (GH3100) s = Series(date_range("20130102", periods=5)) rs = s - s.shift(1) @@ -47,13 +47,13 @@ def test_diff(self): assert_series_equal( result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") ) - + # boolean series s = Series([False, True, True, False, False]) result = s.diff() assert_series_equal(result, Series([nan, True, False, True, False])) - + # boolean nan series s = Series([False, True, nan, False, False]) result = s.diff() - assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype = "object")) + assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) From e028aefa828dfa89a68fc90d3a16764826b36e32 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 6 Aug 2019 17:02:33 +0200 Subject: [PATCH 19/51] Import order changed --- pandas/tests/series/test_diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 7e303be7ee770..1d8c17dfa989b 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -1,7 +1,7 @@ from numpy import nan from pandas import Series, date_range -from pandas.tests.series.common import TestData from pandas.core.indexes.timedeltas import TimedeltaIndex +from pandas.tests.series.common import TestData from pandas.util.testing import assert_series_equal From 9d947dbd6f18a563e882a567dc6035382c8d30cf Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Wed, 7 Aug 2019 13:08:01 +0200 Subject: [PATCH 20/51] Update test_diff.py --- pandas/tests/series/test_diff.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 1d8c17dfa989b..6df0955b96c3d 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -51,9 +51,4 @@ def test_diff(self): # boolean series s = Series([False, True, True, False, False]) result = s.diff() - assert_series_equal(result, Series([nan, True, False, True, False])) - - # boolean nan series - s = Series([False, True, nan, False, False]) - result = s.diff() - assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) + assert_series_equal(result, Series[nan, True, False, True, False]) From b115c9ecf42675ea702bad823f8269e7f5fa763b Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Wed, 7 Aug 2019 13:13:27 +0200 Subject: [PATCH 21/51] Update test_diff.py --- pandas/tests/series/test_diff.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py index 6df0955b96c3d..1d8c17dfa989b 100644 --- a/pandas/tests/series/test_diff.py +++ b/pandas/tests/series/test_diff.py @@ -51,4 +51,9 @@ def test_diff(self): # boolean series s = Series([False, True, True, False, False]) result = s.diff() - assert_series_equal(result, Series[nan, True, False, True, False]) + assert_series_equal(result, Series([nan, True, False, True, False])) + + # boolean nan series + s = Series([False, True, nan, False, False]) + result = s.diff() + assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) From 865e91388624ebb1da3eab25e18a50f61782262f Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sat, 10 Aug 2019 20:33:06 +0200 Subject: [PATCH 22/51] Moving test_diff.py to test_analytics.py As requested... --- pandas/tests/series/test_analytics.py | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 3a5a387b919be..388f1768ffd0c 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -20,6 +20,7 @@ from pandas.api.types import is_scalar from pandas.core.index import MultiIndex from pandas.core.indexes.datetimes import Timestamp +from pandas.core.indexes.timedeltas import TimedeltaIndex import pandas.util.testing as tm from pandas.util.testing import ( assert_almost_equal, @@ -236,7 +237,62 @@ def test_npdiff(self): r = np.diff(s) assert_series_equal(Series([nan, 0, 0, 0, nan]), r) + + def test_diff(self): + ''' + Combined datetime ranges, normal diff and boolean diff test. + ''' + # Just run the function + self.ts.diff() + + # int dtype + a = 10000000000000000 + b = a + 1 + s = Series([a, b]) + + rs = s.diff() + assert rs[1] == 1 + + # neg n + rs = self.ts.diff(-1) + xp = self.ts - self.ts.shift(-1) + assert_series_equal(rs, xp) + + # 0 + rs = self.ts.diff(0) + xp = self.ts - self.ts + assert_series_equal(rs, xp) + + # datetime diff (GH3100) + s = Series(date_range("20130102", periods=5)) + rs = s - s.shift(1) + xp = s.diff() + assert_series_equal(rs, xp) + + # timedelta diff + nrs = rs - rs.shift(1) + nxp = xp.diff() + assert_series_equal(nrs, nxp) + + # with tz + s = Series( + date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" + ) + result = s.diff() + assert_series_equal( + result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") + ) + + # boolean series + s = Series([False, True, True, False, False]) + result = s.diff() + assert_series_equal(result, Series([nan, True, False, True, False])) + # boolean nan series + s = Series([False, True, nan, False, False]) + result = s.diff() + assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) + def _check_accum_op(self, name, datetime_series_, check_dtype=True): func = getattr(np, name) tm.assert_numpy_array_equal( From 6f8986b7fe4bd286c8f8116c3ba066762996da9a Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sat, 10 Aug 2019 20:34:58 +0200 Subject: [PATCH 23/51] Removed test_diff.py, added to test_analytics --- pandas/tests/series/test_diff.py | 59 -------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 pandas/tests/series/test_diff.py diff --git a/pandas/tests/series/test_diff.py b/pandas/tests/series/test_diff.py deleted file mode 100644 index 1d8c17dfa989b..0000000000000 --- a/pandas/tests/series/test_diff.py +++ /dev/null @@ -1,59 +0,0 @@ -from numpy import nan -from pandas import Series, date_range -from pandas.core.indexes.timedeltas import TimedeltaIndex -from pandas.tests.series.common import TestData -from pandas.util.testing import assert_series_equal - - -class TestDiff(TestData): - def test_diff(self): - # Just run the function - self.ts.diff() - - # int dtype - a = 10000000000000000 - b = a + 1 - s = Series([a, b]) - - rs = s.diff() - assert rs[1] == 1 - - # neg n - rs = self.ts.diff(-1) - xp = self.ts - self.ts.shift(-1) - assert_series_equal(rs, xp) - - # 0 - rs = self.ts.diff(0) - xp = self.ts - self.ts - assert_series_equal(rs, xp) - - # datetime diff (GH3100) - s = Series(date_range("20130102", periods=5)) - rs = s - s.shift(1) - xp = s.diff() - assert_series_equal(rs, xp) - - # timedelta diff - nrs = rs - rs.shift(1) - nxp = xp.diff() - assert_series_equal(nrs, nxp) - - # with tz - s = Series( - date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" - ) - result = s.diff() - assert_series_equal( - result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") - ) - - # boolean series - s = Series([False, True, True, False, False]) - result = s.diff() - assert_series_equal(result, Series([nan, True, False, True, False])) - - # boolean nan series - s = Series([False, True, nan, False, False]) - result = s.diff() - assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) From 081c2c8117b58dd2292d19110599b6045472cc82 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sat, 10 Aug 2019 20:43:13 +0200 Subject: [PATCH 24/51] Removing tailing whitespaces --- pandas/tests/series/test_analytics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 388f1768ffd0c..30cf9c6fd2bd8 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -237,7 +237,7 @@ def test_npdiff(self): r = np.diff(s) assert_series_equal(Series([nan, 0, 0, 0, nan]), r) - + def test_diff(self): ''' Combined datetime ranges, normal diff and boolean diff test. @@ -292,7 +292,7 @@ def test_diff(self): s = Series([False, True, nan, False, False]) result = s.diff() assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) - + def _check_accum_op(self, name, datetime_series_, check_dtype=True): func = getattr(np, name) tm.assert_numpy_array_equal( From 96bb1b420b779c7489a0e822429f97520ab325ad Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sat, 10 Aug 2019 22:13:57 +0200 Subject: [PATCH 25/51] STYLE: Black formatting --- pandas/tests/series/test_analytics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 30cf9c6fd2bd8..1d827ced89a08 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -239,9 +239,9 @@ def test_npdiff(self): assert_series_equal(Series([nan, 0, 0, 0, nan]), r) def test_diff(self): - ''' + """ Combined datetime ranges, normal diff and boolean diff test. - ''' + """ # Just run the function self.ts.diff() From 91ebae51144f6d6b66fefd00d4d47bc42e3cee41 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sat, 10 Aug 2019 22:16:04 +0200 Subject: [PATCH 26/51] Update test_analytics.py --- pandas/tests/series/test_analytics.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 1d827ced89a08..81331eeccdb7e 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -239,9 +239,7 @@ def test_npdiff(self): assert_series_equal(Series([nan, 0, 0, 0, nan]), r) def test_diff(self): - """ - Combined datetime ranges, normal diff and boolean diff test. - """ + # Combined datetime diff, normal diff and boolean diff test # Just run the function self.ts.diff() From 74a474f58fd2f6a2677ee31f5e6eee0f6cfaad59 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sat, 10 Aug 2019 22:16:27 +0200 Subject: [PATCH 27/51] Update test_analytics.py --- pandas/tests/series/test_analytics.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 81331eeccdb7e..877b4baddf839 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -240,7 +240,6 @@ def test_npdiff(self): def test_diff(self): # Combined datetime diff, normal diff and boolean diff test - # Just run the function self.ts.diff() # int dtype From 40df511e671b8ac2b7538ff1e1db4e59f91db21f Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sat, 10 Aug 2019 22:33:59 +0200 Subject: [PATCH 28/51] Removing self.ts from code --- pandas/tests/series/test_analytics.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 877b4baddf839..c07f6e903d353 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -240,7 +240,8 @@ def test_npdiff(self): def test_diff(self): # Combined datetime diff, normal diff and boolean diff test - self.ts.diff() + ts = pd.Series([1, 2]) + ts.diff() # int dtype a = 10000000000000000 @@ -251,13 +252,13 @@ def test_diff(self): assert rs[1] == 1 # neg n - rs = self.ts.diff(-1) - xp = self.ts - self.ts.shift(-1) + rs = ts.diff(-1) + xp = ts - ts.shift(-1) assert_series_equal(rs, xp) # 0 - rs = self.ts.diff(0) - xp = self.ts - self.ts + rs = ts.diff(0) + xp = ts - ts assert_series_equal(rs, xp) # datetime diff (GH3100) From 18a2e356f644515916f541f781bf3e55ca5876ee Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sun, 11 Aug 2019 00:09:07 +0200 Subject: [PATCH 29/51] Update test_analytics.py --- pandas/tests/series/test_analytics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index c07f6e903d353..e916edc0bc799 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -238,9 +238,9 @@ def test_npdiff(self): r = np.diff(s) assert_series_equal(Series([nan, 0, 0, 0, nan]), r) - def test_diff(self): + def test_dt_nm_bool_diff(self): # Combined datetime diff, normal diff and boolean diff test - ts = pd.Series([1, 2]) + ts = Series([1, 2, 3]) ts.diff() # int dtype From 716a70e9fd94828e9c3f6ffb8802e83527dce173 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sun, 11 Aug 2019 00:53:38 +0200 Subject: [PATCH 30/51] Adding tm.makeTimeSeries, as in the original --- pandas/tests/series/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index e916edc0bc799..d60df28df06bb 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -240,7 +240,7 @@ def test_npdiff(self): def test_dt_nm_bool_diff(self): # Combined datetime diff, normal diff and boolean diff test - ts = Series([1, 2, 3]) + ts = tm.makeTimeSeries(name='ts') ts.diff() # int dtype From e879dd7fc384b5e58677e91c36c53389e23f937f Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sun, 11 Aug 2019 01:56:41 +0200 Subject: [PATCH 31/51] STYLE: Black --- pandas/tests/series/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d60df28df06bb..d329097ddc666 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -240,7 +240,7 @@ def test_npdiff(self): def test_dt_nm_bool_diff(self): # Combined datetime diff, normal diff and boolean diff test - ts = tm.makeTimeSeries(name='ts') + ts = tm.makeTimeSeries(name="ts") ts.diff() # int dtype From 850e315284d15bb51f12df3ba56755057b826c9c Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 2 Sep 2019 15:30:07 +0200 Subject: [PATCH 32/51] Adding updates --- pandas/core/arrays/datetimes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 70df708d36b3b..732f819e743a4 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1063,6 +1063,7 @@ def tz_localize(self, tz, ambiguous="raise", nonexistent="raise", errors=None): Be careful with DST changes. When there is sequential data, pandas can infer the DST time: + >>> s = pd.to_datetime(pd.Series(['2018-10-28 01:30:00', ... '2018-10-28 02:00:00', ... '2018-10-28 02:30:00', @@ -1094,6 +1095,7 @@ def tz_localize(self, tz, ambiguous="raise", nonexistent="raise", errors=None): If the DST transition causes nonexistent times, you can shift these dates forward or backwards with a timedelta object or `'shift_forward'` or `'shift_backwards'`. + >>> s = pd.to_datetime(pd.Series(['2015-03-29 02:30:00', ... '2015-03-29 03:30:00'])) >>> s.dt.tz_localize('Europe/Warsaw', nonexistent='shift_forward') From 8d2547a754e37295f96a2d0a1ccf899fc8f3d6a8 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 2 Sep 2019 15:46:41 +0200 Subject: [PATCH 33/51] BUG: Fix numpy boolean subtraction error in Series.diff (#27755) --- pandas/core/algorithms.py | 4 ++ pandas/tests/series/test_analytics.py | 54 ++++++++++++++++++++++++++ pandas/tests/series/test_timeseries.py | 42 -------------------- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index c0ed198e200f1..1132f7d6ffdfd 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1915,6 +1915,7 @@ def diff(arr, n, axis=0): dtype = arr.dtype is_timedelta = False + is_bool = False if needs_i8_conversion(arr): dtype = np.float64 arr = arr.view("i8") @@ -1923,6 +1924,7 @@ def diff(arr, n, axis=0): elif is_bool_dtype(dtype): dtype = np.object_ + is_bool = True elif is_integer_dtype(dtype): dtype = np.float64 @@ -1962,6 +1964,8 @@ def diff(arr, n, axis=0): result = res - lag result[mask] = na out_arr[res_indexer] = result + elif is_bool: + out_arr[res_indexer] = arr[res_indexer] ^ arr[lag_indexer] else: out_arr[res_indexer] = arr[res_indexer] - arr[lag_indexer] diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 1ddaa4692d741..d6cb7f8d6a8be 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -20,6 +20,7 @@ from pandas.api.types import is_scalar from pandas.core.index import MultiIndex from pandas.core.indexes.datetimes import Timestamp +from pandas.core.indexes.timedeltas import TimedeltaIndex import pandas.util.testing as tm from pandas.util.testing import ( assert_almost_equal, @@ -237,6 +238,59 @@ def test_npdiff(self): r = np.diff(s) assert_series_equal(Series([nan, 0, 0, 0, nan]), r) + def test_dt_nm_bool_diff(self): + # Combined datetime diff, normal diff and boolean diff test + ts = tm.makeTimeSeries(name="ts") + ts.diff() + + # int dtype + a = 10000000000000000 + b = a + 1 + s = Series([a, b]) + + rs = s.diff() + assert rs[1] == 1 + + # neg n + rs = ts.diff(-1) + xp = ts - ts.shift(-1) + assert_series_equal(rs, xp) + + # 0 + rs = ts.diff(0) + xp = ts - ts + assert_series_equal(rs, xp) + + # datetime diff (GH3100) + s = Series(date_range("20130102", periods=5)) + rs = s - s.shift(1) + xp = s.diff() + assert_series_equal(rs, xp) + + # timedelta diff + nrs = rs - rs.shift(1) + nxp = xp.diff() + assert_series_equal(nrs, nxp) + + # with tz + s = Series( + date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" + ) + result = s.diff() + assert_series_equal( + result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") + ) + + # boolean series + s = Series([False, True, True, False, False]) + result = s.diff() + assert_series_equal(result, Series([nan, True, False, True, False])) + + # boolean nan series + s = Series([False, True, nan, False, False]) + result = s.diff() + assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) + def _check_accum_op(self, name, datetime_series_, check_dtype=True): func = getattr(np, name) tm.assert_numpy_array_equal( diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index d0ca5d82c6b33..fbe3f929cf5b5 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -355,48 +355,6 @@ def test_asfreq_datetimeindex_empty_series(self): ) tm.assert_index_equal(expected.index, result.index) - def test_diff(self): - # Just run the function - self.ts.diff() - - # int dtype - a = 10000000000000000 - b = a + 1 - s = Series([a, b]) - - rs = s.diff() - assert rs[1] == 1 - - # neg n - rs = self.ts.diff(-1) - xp = self.ts - self.ts.shift(-1) - assert_series_equal(rs, xp) - - # 0 - rs = self.ts.diff(0) - xp = self.ts - self.ts - assert_series_equal(rs, xp) - - # datetime diff (GH3100) - s = Series(date_range("20130102", periods=5)) - rs = s - s.shift(1) - xp = s.diff() - assert_series_equal(rs, xp) - - # timedelta diff - nrs = rs - rs.shift(1) - nxp = xp.diff() - assert_series_equal(nrs, nxp) - - # with tz - s = Series( - date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" - ) - result = s.diff() - assert_series_equal( - result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") - ) - def test_pct_change(self): rs = self.ts.pct_change(fill_method=None) assert_series_equal(rs, self.ts / self.ts.shift(1) - 1) From 3e0dbc74a39ad5ea197251a86d46dbe593b241d6 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 2 Sep 2019 16:27:10 +0200 Subject: [PATCH 34/51] Update v0.25.2.rst Adding fix to Other --- doc/source/whatsnew/v0.25.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.2.rst b/doc/source/whatsnew/v0.25.2.rst index 1cdf213d81a74..675469099735c 100644 --- a/doc/source/whatsnew/v0.25.2.rst +++ b/doc/source/whatsnew/v0.25.2.rst @@ -100,7 +100,7 @@ Other ^^^^^ - Compatibility with Python 3.8 in :meth:`DataFrame.query` (:issue:`27261`) -- +- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 (:issue:`17294`) .. _whatsnew_0.252.contributors: From f98cbf20aeb5fc932eb697feecf6ab8d873357f3 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 2 Sep 2019 16:48:30 +0200 Subject: [PATCH 35/51] Update v0.25.1.rst --- doc/source/whatsnew/v0.25.1.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v0.25.1.rst b/doc/source/whatsnew/v0.25.1.rst index f246a7f87c9b4..63dd56f4a3793 100644 --- a/doc/source/whatsnew/v0.25.1.rst +++ b/doc/source/whatsnew/v0.25.1.rst @@ -109,10 +109,7 @@ Other ^^^^^ - Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` when replacing timezone-aware timestamps using a dict-like replacer (:issue:`27720`) -- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 (:issue:`17294`) -- -- ->>>>>>> patch-1 +- Bug in :meth:`Series.rename` when using a custom type indexer. Now any value that isn't callable or dict-like is treated as a scalar. (:issue:`27814`) .. _whatsnew_0.251.contributors: From 212765126539f52245b732170c8273c6dcf27524 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 3 Sep 2019 09:01:18 +0200 Subject: [PATCH 36/51] Refactored code and added version number --- doc/source/whatsnew/v0.25.2.rst | 2 +- doc/source/whatsnew/v1.0.0.rst | 1 + pandas/tests/series/test_analytics.py | 40 +++++++++++++++------------ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/doc/source/whatsnew/v0.25.2.rst b/doc/source/whatsnew/v0.25.2.rst index 675469099735c..6cdec5a1c636d 100644 --- a/doc/source/whatsnew/v0.25.2.rst +++ b/doc/source/whatsnew/v0.25.2.rst @@ -100,7 +100,7 @@ Other ^^^^^ - Compatibility with Python 3.8 in :meth:`DataFrame.query` (:issue:`27261`) -- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 (:issue:`17294`) +- .. _whatsnew_0.252.contributors: diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 3b6288146bdf2..5c27264c51761 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -211,6 +211,7 @@ Other - Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using :meth:`set_option` to anything but a ``None`` or a positive int will raise a ``ValueError`` (:issue:`23348`) - Using :meth:`DataFrame.replace` with overlapping keys in a nested dictionary will no longer raise, now matching the behavior of a flat dictionary (:issue:`27660`) - :meth:`DataFrame.to_csv` and :meth:`Series.to_csv` now support dicts as ``compression`` argument with key ``'method'`` being the compression method and others as additional compression options when the compression method is ``'zip'``. (:issue:`26023`) +- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 (:issue:`17294`) .. _whatsnew_1000.contributors: diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d6cb7f8d6a8be..b2e8b08ce920a 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -238,7 +238,7 @@ def test_npdiff(self): r = np.diff(s) assert_series_equal(Series([nan, 0, 0, 0, nan]), r) - def test_dt_nm_bool_diff(self): + def test_diff(self): # Combined datetime diff, normal diff and boolean diff test ts = tm.makeTimeSeries(name="ts") ts.diff() @@ -248,48 +248,52 @@ def test_dt_nm_bool_diff(self): b = a + 1 s = Series([a, b]) - rs = s.diff() - assert rs[1] == 1 + result = s.diff() + assert result[1] == 1 # neg n - rs = ts.diff(-1) - xp = ts - ts.shift(-1) - assert_series_equal(rs, xp) + result = ts.diff(-1) + expected = ts - ts.shift(-1) + assert_series_equal(result, expected) # 0 - rs = ts.diff(0) - xp = ts - ts - assert_series_equal(rs, xp) + result = ts.diff(0) + expected = ts - ts + assert_series_equal(result, expected) # datetime diff (GH3100) s = Series(date_range("20130102", periods=5)) - rs = s - s.shift(1) - xp = s.diff() - assert_series_equal(rs, xp) + result = s - s.shift(1) + expected = s.diff() + assert_series_equal(result, expected) # timedelta diff - nrs = rs - rs.shift(1) - nxp = xp.diff() - assert_series_equal(nrs, nxp) + result = rs - rs.shift(1) + expected = xp.diff() + assert_series_equal(result, expected) # with tz s = Series( date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" ) result = s.diff() + expected = Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4) assert_series_equal( - result, Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") + result, expected, name="foo") ) + # tests added for fix #17294 # boolean series s = Series([False, True, True, False, False]) result = s.diff() - assert_series_equal(result, Series([nan, True, False, True, False])) + expected = Series([nan, True, False, True, False]) + assert_series_equal(result, expected) # boolean nan series s = Series([False, True, nan, False, False]) result = s.diff() - assert_series_equal(result, Series([nan, 1, nan, nan, 0], dtype="object")) + expected = Series([nan, 1, nan, nan, 0], dtype="object") + assert_series_equal(result, expected) def _check_accum_op(self, name, datetime_series_, check_dtype=True): func = getattr(np, name) From b83135d21171de51f2e59206ea4fa2569cb31b37 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 3 Sep 2019 09:24:41 +0200 Subject: [PATCH 37/51] Fixing typo --- pandas/tests/series/test_analytics.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index b2e8b08ce920a..cafaad0e14921 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -277,10 +277,8 @@ def test_diff(self): date_range("2000-01-01 09:00:00", periods=5, tz="US/Eastern"), name="foo" ) result = s.diff() - expected = Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4) - assert_series_equal( - result, expected, name="foo") - ) + expected = Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") + assert_series_equal(result, expected) # tests added for fix #17294 # boolean series From b14f7c6b70356d3cfb43258a296858e40f750513 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 3 Sep 2019 09:26:37 +0200 Subject: [PATCH 38/51] Moving comment --- pandas/tests/series/test_analytics.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index cafaad0e14921..37ed2a1b93595 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -280,8 +280,7 @@ def test_diff(self): expected = Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") assert_series_equal(result, expected) - # tests added for fix #17294 - # boolean series + # boolean series (test for fixing #17294) s = Series([False, True, True, False, False]) result = s.diff() expected = Series([nan, True, False, True, False]) From d92d6c79466fd0c7149de17c39f5d55a4cdf5222 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 3 Sep 2019 09:31:47 +0200 Subject: [PATCH 39/51] Removed a space --- doc/source/whatsnew/v0.25.2.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.2.rst b/doc/source/whatsnew/v0.25.2.rst index 6cdec5a1c636d..1cdf213d81a74 100644 --- a/doc/source/whatsnew/v0.25.2.rst +++ b/doc/source/whatsnew/v0.25.2.rst @@ -100,7 +100,7 @@ Other ^^^^^ - Compatibility with Python 3.8 in :meth:`DataFrame.query` (:issue:`27261`) -- +- .. _whatsnew_0.252.contributors: From b96bde8a5fc6132603081db9512ccc15c77f4180 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 3 Sep 2019 13:34:36 +0200 Subject: [PATCH 40/51] Fixed typo --- pandas/tests/series/test_analytics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 37ed2a1b93595..d22306d9682e1 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -268,8 +268,8 @@ def test_diff(self): assert_series_equal(result, expected) # timedelta diff - result = rs - rs.shift(1) - expected = xp.diff() + result = result - result.shift(1) # previous result + expected = expected.diff() # previously expected assert_series_equal(result, expected) # with tz From 6a72f2c221297ddced5e4837c424b8185e0a4a99 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 3 Sep 2019 14:14:05 +0200 Subject: [PATCH 41/51] Added spaces --- pandas/tests/series/test_analytics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index d22306d9682e1..040e029eb98e9 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -268,8 +268,8 @@ def test_diff(self): assert_series_equal(result, expected) # timedelta diff - result = result - result.shift(1) # previous result - expected = expected.diff() # previously expected + result = result - result.shift(1) # previous result + expected = expected.diff() # previously expected assert_series_equal(result, expected) # with tz From 030d305b69ea685ac53e380336830573d798ba9b Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 3 Sep 2019 14:25:36 +0200 Subject: [PATCH 42/51] Fixed typo --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 5c27264c51761..fb77a2ecdd112 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -211,7 +211,7 @@ Other - Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using :meth:`set_option` to anything but a ``None`` or a positive int will raise a ``ValueError`` (:issue:`23348`) - Using :meth:`DataFrame.replace` with overlapping keys in a nested dictionary will no longer raise, now matching the behavior of a flat dictionary (:issue:`27660`) - :meth:`DataFrame.to_csv` and :meth:`Series.to_csv` now support dicts as ``compression`` argument with key ``'method'`` being the compression method and others as additional compression options when the compression method is ``'zip'``. (:issue:`26023`) -- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 0.13.0 (:issue:`17294`) +- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 1.13.0 (:issue:`17294`) .. _whatsnew_1000.contributors: From 649042fce9bcf8ffc373ca0687289d573cd75acb Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 9 Sep 2019 18:03:40 +0200 Subject: [PATCH 43/51] Adding requirements --- pandas/core/algorithms.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 1132f7d6ffdfd..596ae0ae636c2 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1916,6 +1916,7 @@ def diff(arr, n, axis=0): is_timedelta = False is_bool = False + is_obj_bool = False if needs_i8_conversion(arr): dtype = np.float64 arr = arr.view("i8") @@ -1929,6 +1930,10 @@ def diff(arr, n, axis=0): elif is_integer_dtype(dtype): dtype = np.float64 + elif is_object_dtype(dtype): + if all(np.isin(arr, (True, False), False) == ~isna(arr)): + is_obj_bool = True + dtype = np.dtype(dtype) out_arr = np.empty(arr.shape, dtype=dtype) @@ -1969,6 +1974,13 @@ def diff(arr, n, axis=0): else: out_arr[res_indexer] = arr[res_indexer] - arr[lag_indexer] + if is_obj_bool: + # converting numbers to bool + na_index = isna(out_arr) + out_arr = out_arr.astype(bool).astype(object) + # resetting nan previously converted to True + out_arr[na_index] = np.nan + if is_timedelta: out_arr = out_arr.astype("int64").view("timedelta64[ns]") From d1c1755d39f0baf471d23cd75d3d57e2d655fdb5 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 10 Sep 2019 13:53:54 +0200 Subject: [PATCH 44/51] Updating --- pandas/core/algorithms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 596ae0ae636c2..80ddf40068b9c 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1931,7 +1931,7 @@ def diff(arr, n, axis=0): dtype = np.float64 elif is_object_dtype(dtype): - if all(np.isin(arr, (True, False), False) == ~isna(arr)): + if np.all(np.isin(arr, (True, False), False) | isna(arr)): is_obj_bool = True dtype = np.dtype(dtype) From 1e4a7ae8b997b6727cd47bcbe4eef51677819d0f Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Wed, 11 Sep 2019 11:41:10 +0200 Subject: [PATCH 45/51] Updating documentation --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index fb77a2ecdd112..c89363a82ba1a 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -211,7 +211,7 @@ Other - Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using :meth:`set_option` to anything but a ``None`` or a positive int will raise a ``ValueError`` (:issue:`23348`) - Using :meth:`DataFrame.replace` with overlapping keys in a nested dictionary will no longer raise, now matching the behavior of a flat dictionary (:issue:`27660`) - :meth:`DataFrame.to_csv` and :meth:`Series.to_csv` now support dicts as ``compression`` argument with key ``'method'`` being the compression method and others as additional compression options when the compression method is ``'zip'``. (:issue:`26023`) -- Bug in :meth:`Series.diff` where a boolean series would cause a TypeError (the - operator is deprecated) when using NumPy >= 1.13.0 (:issue:`17294`) +- Bug in :meth:`Series.diff` where a boolean series would incorrectly raise a TypeError (the - operator is deprecated) (:issue:`17294`) .. _whatsnew_1000.contributors: From d1c6b6577f3068d5fcfd96a7bc0a5b36434e687c Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Thu, 12 Sep 2019 09:30:34 +0200 Subject: [PATCH 46/51] Adding object series test --- pandas/tests/series/test_analytics.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 040e029eb98e9..bd64df654f394 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -263,8 +263,8 @@ def test_diff(self): # datetime diff (GH3100) s = Series(date_range("20130102", periods=5)) - result = s - s.shift(1) - expected = s.diff() + result = s.diff() + expected = s - s.shift(1) assert_series_equal(result, expected) # timedelta diff @@ -286,10 +286,10 @@ def test_diff(self): expected = Series([nan, True, False, True, False]) assert_series_equal(result, expected) - # boolean nan series - s = Series([False, True, nan, False, False]) + # object series + s = Series([False, True, 5.0, nan, True, False]) result = s.diff() - expected = Series([nan, 1, nan, nan, 0], dtype="object") + expected = s - s.shift(1) assert_series_equal(result, expected) def _check_accum_op(self, name, datetime_series_, check_dtype=True): From bbd2550c5d6c31091c5fbcec14d144b0d2720010 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Sun, 15 Sep 2019 20:39:21 +0200 Subject: [PATCH 47/51] Removing the extra object NaN code --- pandas/core/algorithms.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 80ddf40068b9c..1132f7d6ffdfd 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1916,7 +1916,6 @@ def diff(arr, n, axis=0): is_timedelta = False is_bool = False - is_obj_bool = False if needs_i8_conversion(arr): dtype = np.float64 arr = arr.view("i8") @@ -1930,10 +1929,6 @@ def diff(arr, n, axis=0): elif is_integer_dtype(dtype): dtype = np.float64 - elif is_object_dtype(dtype): - if np.all(np.isin(arr, (True, False), False) | isna(arr)): - is_obj_bool = True - dtype = np.dtype(dtype) out_arr = np.empty(arr.shape, dtype=dtype) @@ -1974,13 +1969,6 @@ def diff(arr, n, axis=0): else: out_arr[res_indexer] = arr[res_indexer] - arr[lag_indexer] - if is_obj_bool: - # converting numbers to bool - na_index = isna(out_arr) - out_arr = out_arr.astype(bool).astype(object) - # resetting nan previously converted to True - out_arr[na_index] = np.nan - if is_timedelta: out_arr = out_arr.astype("int64").view("timedelta64[ns]") From 21defe64549a0b76195818aa5420bf2c28b15168 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 23 Sep 2019 16:10:58 +0200 Subject: [PATCH 48/51] Adding requirements Looks like I will be parametrizing and splitting the function into several functions. If there are no bugs, this should do. --- pandas/tests/series/test_analytics.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index bd64df654f394..6bfba0576d634 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -229,7 +229,7 @@ def test_cummax_timedelta64(self): result = s.cummax(skipna=False) tm.assert_series_equal(expected, result) - def test_npdiff(self): + def test_np_diff(self): pytest.skip("skipping due to Series no longer being an ndarray") # no longer works as the return type of np.diff is now nd.array @@ -238,11 +238,7 @@ def test_npdiff(self): r = np.diff(s) assert_series_equal(Series([nan, 0, 0, 0, nan]), r) - def test_diff(self): - # Combined datetime diff, normal diff and boolean diff test - ts = tm.makeTimeSeries(name="ts") - ts.diff() - + def test_int_diff(self): # int dtype a = 10000000000000000 b = a + 1 @@ -251,6 +247,11 @@ def test_diff(self): result = s.diff() assert result[1] == 1 + def test_tz_diff(self): + # Combined datetime diff, normal diff and boolean diff test + ts = tm.makeTimeSeries(name="ts") + ts.diff() + # neg n result = ts.diff(-1) expected = ts - ts.shift(-1) @@ -280,12 +281,17 @@ def test_diff(self): expected = Series(TimedeltaIndex(["NaT"] + ["1 days"] * 4), name="foo") assert_series_equal(result, expected) + @pytest.mark.parametrize( + "input,output,diff", [([False, True, True, False, False], [nan, True, False, True, False], 1)] + ) + def test_bool_diff(self, input, output, diff): # boolean series (test for fixing #17294) - s = Series([False, True, True, False, False]) + s = Series(input) result = s.diff() - expected = Series([nan, True, False, True, False]) + expected = Series(output) assert_series_equal(result, expected) + def test_obj_diff(self): # object series s = Series([False, True, 5.0, nan, True, False]) result = s.diff() From 62275649302be16b33febc3e8f6014910adb80ab Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 23 Sep 2019 16:50:25 +0200 Subject: [PATCH 49/51] BLACK formatting --- pandas/tests/series/test_analytics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 6bfba0576d634..8f19f3000df30 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -282,7 +282,8 @@ def test_tz_diff(self): assert_series_equal(result, expected) @pytest.mark.parametrize( - "input,output,diff", [([False, True, True, False, False], [nan, True, False, True, False], 1)] + "input,output,diff", + [([False, True, True, False, False], [nan, True, False, True, False], 1)] ) def test_bool_diff(self, input, output, diff): # boolean series (test for fixing #17294) From 88cea85f03d3d4a6f6e2425a1d3bd7904c719bb8 Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Tue, 24 Sep 2019 10:03:03 +0200 Subject: [PATCH 50/51] Adding comma --- pandas/tests/series/test_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 8f19f3000df30..08aa3ad02e0ed 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -283,7 +283,7 @@ def test_tz_diff(self): @pytest.mark.parametrize( "input,output,diff", - [([False, True, True, False, False], [nan, True, False, True, False], 1)] + [([False, True, True, False, False], [nan, True, False, True, False], 1)], ) def test_bool_diff(self, input, output, diff): # boolean series (test for fixing #17294) From acc8f87b734b4c6a09bdf14d3cf37dc1e558c93f Mon Sep 17 00:00:00 2001 From: Unprocessable Date: Mon, 30 Sep 2019 13:22:16 +0200 Subject: [PATCH 51/51] Changing bug description Changing the description again. The numpy version and 'the - operator is deprecated' are now both removed. --- doc/source/whatsnew/v1.0.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 9690621207e2d..37f559e45ec71 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -240,7 +240,7 @@ Other - Trying to set the ``display.precision``, ``display.max_rows`` or ``display.max_columns`` using :meth:`set_option` to anything but a ``None`` or a positive int will raise a ``ValueError`` (:issue:`23348`) - Using :meth:`DataFrame.replace` with overlapping keys in a nested dictionary will no longer raise, now matching the behavior of a flat dictionary (:issue:`27660`) - :meth:`DataFrame.to_csv` and :meth:`Series.to_csv` now support dicts as ``compression`` argument with key ``'method'`` being the compression method and others as additional compression options when the compression method is ``'zip'``. (:issue:`26023`) -- Bug in :meth:`Series.diff` where a boolean series would incorrectly raise a TypeError (the - operator is deprecated) (:issue:`17294`) +- Bug in :meth:`Series.diff` where a boolean series would incorrectly raise a ``TypeError`` (:issue:`17294`) - :meth:`Series.append` will no longer raise a ``TypeError`` when passed a tuple of ``Series`` (:issue:`28410`) .. _whatsnew_1000.contributors: