From 215a0494ddf6501e003963e28158958a11c7657e Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 11:18:41 -0400 Subject: [PATCH 01/21] Added in a regression test for issue #25257. Verified that it fails on version 0.24.1 but passes on current version --- pandas/tests/dtypes/test_concat.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index 1fbbd3356ae13..f2be8985aa26f 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -88,3 +88,13 @@ def test_concat_mismatched_categoricals_with_empty(): result = _concat.concat_compat([ser1._values, ser2._values]) expected = pd.concat([ser1, ser2])._values tm.assert_categorical_equal(result, expected) + +#This will raise a ValueError issue if it fails +#Regression test for issue 25257 +def test_no_tz_concat_without_copy(): + df = pd.DataFrame({ + 'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], + }) + pd.concat([df], copy=False) + + From a8748aa7ba6d3a979490e07b078b0218474eb6a6 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 11:34:19 -0400 Subject: [PATCH 02/21] style changes --- pandas/tests/dtypes/test_concat.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index f2be8985aa26f..2d0ccd6315efd 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -89,12 +89,11 @@ def test_concat_mismatched_categoricals_with_empty(): expected = pd.concat([ser1, ser2])._values tm.assert_categorical_equal(result, expected) -#This will raise a ValueError issue if it fails -#Regression test for issue 25257 + +# This will raise a ValueError issue if it fails +# Regression test for issue 25257 def test_no_tz_concat_without_copy(): df = pd.DataFrame({ 'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], }) pd.concat([df], copy=False) - - From 93be1c4ac3f8a0b0eb48878e47d53001f0ee2c7b Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 12:43:14 -0400 Subject: [PATCH 03/21] Added in assert statement --- pandas/tests/dtypes/test_concat.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index 2d0ccd6315efd..d2047387db602 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -90,10 +90,13 @@ def test_concat_mismatched_categoricals_with_empty(): tm.assert_categorical_equal(result, expected) -# This will raise a ValueError issue if it fails -# Regression test for issue 25257 + def test_no_tz_concat_without_copy(): - df = pd.DataFrame({ - 'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], - }) - pd.concat([df], copy=False) + # This will raise a ValueError issue if it fails + # Regression test for issue 25257 + df = pd.DataFrame({ + 'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], + }) + result = pd.concat([df], copy=False) + expected = df + tm.assert_frame_equal(result, expected) From a0caac6f205e600494c79b884c4e96f130103825 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 13:19:04 -0400 Subject: [PATCH 04/21] indentation fixes --- pandas/tests/dtypes/test_concat.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index d2047387db602..ec50ff788a4ee 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -90,13 +90,10 @@ def test_concat_mismatched_categoricals_with_empty(): tm.assert_categorical_equal(result, expected) - def test_no_tz_concat_without_copy(): - # This will raise a ValueError issue if it fails - # Regression test for issue 25257 - df = pd.DataFrame({ - 'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], - }) - result = pd.concat([df], copy=False) - expected = df - tm.assert_frame_equal(result, expected) + # This will raise a ValueError issue if it fails + # Regression test for issue 25257 + df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')],}) + result = pd.concat([df], copy=False) + expected = df + tm.assert_frame_equal(result, expected) \ No newline at end of file From 9f37013e0b96d4df1744808b1e17ec3ed25586bd Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 13:21:57 -0400 Subject: [PATCH 05/21] Whitespace fixes --- pandas/tests/dtypes/test_concat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index ec50ff788a4ee..869fc467bee35 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -93,7 +93,8 @@ def test_concat_mismatched_categoricals_with_empty(): def test_no_tz_concat_without_copy(): # This will raise a ValueError issue if it fails # Regression test for issue 25257 - df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')],}) + df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', + tz='UTC')],}) result = pd.concat([df], copy=False) expected = df - tm.assert_frame_equal(result, expected) \ No newline at end of file + tm.assert_frame_equal(result, expected) From d0ce00e22463c32b46a404b77cf2fa36991f84bd Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 13:24:25 -0400 Subject: [PATCH 06/21] indentation fixes --- pandas/tests/dtypes/test_concat.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index 869fc467bee35..b198254363b7d 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -93,8 +93,8 @@ def test_concat_mismatched_categoricals_with_empty(): def test_no_tz_concat_without_copy(): # This will raise a ValueError issue if it fails # Regression test for issue 25257 - df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', - tz='UTC')],}) + df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', + tz='UTC')], }) result = pd.concat([df], copy=False) expected = df tm.assert_frame_equal(result, expected) From 6e33152c59ecf9a7a2ba3ba686170cd8faeccbce Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 16:15:15 -0400 Subject: [PATCH 07/21] fixed spacing --- pandas/tests/dtypes/test_concat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index b198254363b7d..bbd69a4892cde 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -94,7 +94,7 @@ def test_no_tz_concat_without_copy(): # This will raise a ValueError issue if it fails # Regression test for issue 25257 df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', - tz='UTC')], }) + tz='UTC')], }) result = pd.concat([df], copy=False) expected = df tm.assert_frame_equal(result, expected) From ce8fa9ce687a4f0ec788c44c2d685d2d11dcddce Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 10 Apr 2020 16:18:33 -0400 Subject: [PATCH 08/21] Indentation fixes --- pandas/tests/dtypes/test_concat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index bbd69a4892cde..de514a87cd777 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -94,7 +94,7 @@ def test_no_tz_concat_without_copy(): # This will raise a ValueError issue if it fails # Regression test for issue 25257 df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', - tz='UTC')], }) + tz='UTC')], }) result = pd.concat([df], copy=False) expected = df tm.assert_frame_equal(result, expected) From de1373e50c8edfc9db2ef59d86a5afe476cdd0d7 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Mon, 13 Apr 2020 19:45:10 -0400 Subject: [PATCH 09/21] Paramterized Copy-False --- pandas/tests/dtypes/test_concat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index de514a87cd777..88c0b97495989 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -90,11 +90,12 @@ def test_concat_mismatched_categoricals_with_empty(): tm.assert_categorical_equal(result, expected) -def test_no_tz_concat_without_copy(): +@pytest.mark.parametrize("_COPY_", [True, False]) +def test_no_tz_concat_without_copy(_COPY_): # This will raise a ValueError issue if it fails # Regression test for issue 25257 df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], }) - result = pd.concat([df], copy=False) + result = pd.concat([df], copy=_COPY_) expected = df tm.assert_frame_equal(result, expected) From a0c4e2be142dd323d27fc28b5787db68b2816e7b Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Thu, 16 Apr 2020 23:35:21 -0400 Subject: [PATCH 10/21] reformatted test_concat.py --- pandas/tests/dtypes/test_concat.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index 88c0b97495989..038802ace1086 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -94,8 +94,9 @@ def test_concat_mismatched_categoricals_with_empty(): def test_no_tz_concat_without_copy(_COPY_): # This will raise a ValueError issue if it fails # Regression test for issue 25257 - df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', - tz='UTC')], }) + df = pd.DataFrame( + {"timestamp": [pd.Timestamp("2020-04-08 09:00:00.709949+0000", tz="UTC")],} + ) result = pd.concat([df], copy=_COPY_) expected = df tm.assert_frame_equal(result, expected) From f095a740c800866a56077b22c1866b0ddab3636d Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 17 Apr 2020 15:30:29 -0400 Subject: [PATCH 11/21] Made some changes to visit_call. I know its wrong but adding this commit to test out normally with floor(1) + floor(2) --- pandas/core/computation/expr.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index c59952bea8dc0..43effec4cfa54 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -659,11 +659,15 @@ def visit_Call(self, node, side=None, **kwargs): raise ValueError(f"Invalid function call {node.func.id}") if hasattr(res, "value"): res = res.value - - if isinstance(res, FuncNode): - - new_args = [self.visit(arg) for arg in node.args] - + print(type(res)) + if isinstance(res, FuncNode) or isinstance(res, np.ufunc): + # new_args = [self.visit(arg) for arg in node.args] + new_args = [] + for arg in node.args: + temp_visit = self.visit(arg) + if hasattr(temp_visit, "value"): + temp_visit = temp_visit.value + new_args.append(temp_visit) if node.keywords: raise TypeError( f'Function "{res.name}" does not support keyword arguments' @@ -672,9 +676,20 @@ def visit_Call(self, node, side=None, **kwargs): return res(*new_args) else: - + import logging, sys + logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) + logging.debug(str(self.visit(arg).value for arg in node.args)) + logging.debug(ast.dump(node)) + # for arg in node.args: + # logging.debug("this is the next arg") + # logging.debug(arg) + # logging.debug(self.visit(arg).value) + print([self.visit(arg) for arg in node.args]) + + print([self.visit(arg).value for arg in node.args]) new_args = [self.visit(arg).value for arg in node.args] - + # import copy + # new_args = copy.deepcopy(node.args) for key in node.keywords: if not isinstance(key, ast.keyword): raise ValueError(f"keyword error in function call '{node.func.id}'") From ba4e8233db2c8ff015d9d42ddbbfb789281f094e Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 17 Apr 2020 16:13:17 -0400 Subject: [PATCH 12/21] Fixed the bug. Realized that we had to parse and evaluate the inner expression before returning res() of the value which was an abstraction of the floor function being passed in --- pandas/core/computation/expr.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index c59952bea8dc0..731b6f67cc36d 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -670,19 +670,26 @@ def visit_Call(self, node, side=None, **kwargs): ) return res(*new_args) + elif isinstance(res, np.ufunc): + new_args = [self.visit(arg) for arg in node.args] + new_args = str(*new_args) + new_args = [eval(new_args)] + if node.keywords: + raise TypeError( + f'Function "{res.name}" does not support keyword arguments' + ) else: - new_args = [self.visit(arg).value for arg in node.args] - for key in node.keywords: - if not isinstance(key, ast.keyword): - raise ValueError(f"keyword error in function call '{node.func.id}'") + for key in node.keywords: + if not isinstance(key, ast.keyword): + raise ValueError(f"keyword error in function call '{node.func.id}'") - if key.arg: - kwargs[key.arg] = self.visit(key.value).value + if key.arg: + kwargs[key.arg] = self.visit(key.value).value - return self.const_type(res(*new_args, **kwargs), self.env) + return self.const_type(res(*new_args, **kwargs), self.env) def translate_In(self, op): return op From 02918280232b5cb67bb3a58492b91fc8b733cc1c Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 17 Apr 2020 16:20:00 -0400 Subject: [PATCH 13/21] Revert "Made some changes to visit_call. I know its wrong but adding this commit to test out normally with floor(1) + floor(2)" This reverts commit f095a740c800866a56077b22c1866b0ddab3636d. --- pandas/core/computation/expr.py | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index 43effec4cfa54..c59952bea8dc0 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -659,15 +659,11 @@ def visit_Call(self, node, side=None, **kwargs): raise ValueError(f"Invalid function call {node.func.id}") if hasattr(res, "value"): res = res.value - print(type(res)) - if isinstance(res, FuncNode) or isinstance(res, np.ufunc): - # new_args = [self.visit(arg) for arg in node.args] - new_args = [] - for arg in node.args: - temp_visit = self.visit(arg) - if hasattr(temp_visit, "value"): - temp_visit = temp_visit.value - new_args.append(temp_visit) + + if isinstance(res, FuncNode): + + new_args = [self.visit(arg) for arg in node.args] + if node.keywords: raise TypeError( f'Function "{res.name}" does not support keyword arguments' @@ -676,20 +672,9 @@ def visit_Call(self, node, side=None, **kwargs): return res(*new_args) else: - import logging, sys - logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) - logging.debug(str(self.visit(arg).value for arg in node.args)) - logging.debug(ast.dump(node)) - # for arg in node.args: - # logging.debug("this is the next arg") - # logging.debug(arg) - # logging.debug(self.visit(arg).value) - print([self.visit(arg) for arg in node.args]) - - print([self.visit(arg).value for arg in node.args]) + new_args = [self.visit(arg).value for arg in node.args] - # import copy - # new_args = copy.deepcopy(node.args) + for key in node.keywords: if not isinstance(key, ast.keyword): raise ValueError(f"keyword error in function call '{node.func.id}'") From f63c5bd9ac0cfe32af1ea4f7973140a64a578732 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 17 Apr 2020 16:20:00 -0400 Subject: [PATCH 14/21] Revert "reformatted test_concat.py" This reverts commit a0c4e2be142dd323d27fc28b5787db68b2816e7b. --- pandas/tests/dtypes/test_concat.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index 038802ace1086..88c0b97495989 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -94,9 +94,8 @@ def test_concat_mismatched_categoricals_with_empty(): def test_no_tz_concat_without_copy(_COPY_): # This will raise a ValueError issue if it fails # Regression test for issue 25257 - df = pd.DataFrame( - {"timestamp": [pd.Timestamp("2020-04-08 09:00:00.709949+0000", tz="UTC")],} - ) + df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', + tz='UTC')], }) result = pd.concat([df], copy=_COPY_) expected = df tm.assert_frame_equal(result, expected) From af1ea2a440649074cc38fdd1280e5807e1d9678e Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 17 Apr 2020 16:20:00 -0400 Subject: [PATCH 15/21] Revert "Paramterized Copy-False" This reverts commit de1373e50c8edfc9db2ef59d86a5afe476cdd0d7. --- pandas/tests/dtypes/test_concat.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index 88c0b97495989..de514a87cd777 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -90,12 +90,11 @@ def test_concat_mismatched_categoricals_with_empty(): tm.assert_categorical_equal(result, expected) -@pytest.mark.parametrize("_COPY_", [True, False]) -def test_no_tz_concat_without_copy(_COPY_): +def test_no_tz_concat_without_copy(): # This will raise a ValueError issue if it fails # Regression test for issue 25257 df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], }) - result = pd.concat([df], copy=_COPY_) + result = pd.concat([df], copy=False) expected = df tm.assert_frame_equal(result, expected) From 85dd8614066b62839ef7c549cd1ca0173a166874 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 17 Apr 2020 16:20:00 -0400 Subject: [PATCH 16/21] Revert "Indentation fixes" This reverts commit ce8fa9ce687a4f0ec788c44c2d685d2d11dcddce. --- pandas/tests/dtypes/test_concat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index de514a87cd777..bbd69a4892cde 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -94,7 +94,7 @@ def test_no_tz_concat_without_copy(): # This will raise a ValueError issue if it fails # Regression test for issue 25257 df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', - tz='UTC')], }) + tz='UTC')], }) result = pd.concat([df], copy=False) expected = df tm.assert_frame_equal(result, expected) From 243d6509c8c3dcbb6d94c66ac7786313248a7314 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Fri, 17 Apr 2020 16:28:52 -0400 Subject: [PATCH 17/21] Fixed the bug --- pandas/core/computation/expr.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index c59952bea8dc0..731b6f67cc36d 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -670,19 +670,26 @@ def visit_Call(self, node, side=None, **kwargs): ) return res(*new_args) + elif isinstance(res, np.ufunc): + new_args = [self.visit(arg) for arg in node.args] + new_args = str(*new_args) + new_args = [eval(new_args)] + if node.keywords: + raise TypeError( + f'Function "{res.name}" does not support keyword arguments' + ) else: - new_args = [self.visit(arg).value for arg in node.args] - for key in node.keywords: - if not isinstance(key, ast.keyword): - raise ValueError(f"keyword error in function call '{node.func.id}'") + for key in node.keywords: + if not isinstance(key, ast.keyword): + raise ValueError(f"keyword error in function call '{node.func.id}'") - if key.arg: - kwargs[key.arg] = self.visit(key.value).value + if key.arg: + kwargs[key.arg] = self.visit(key.value).value - return self.const_type(res(*new_args, **kwargs), self.env) + return self.const_type(res(*new_args, **kwargs), self.env) def translate_In(self, op): return op From cff2f7df70069bb0ddac077ad572654e31211131 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Mon, 20 Apr 2020 15:47:00 -0400 Subject: [PATCH 18/21] added in whitespace after ',' --- pandas/tests/dtypes/test_concat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index bbd69a4892cde..baa7882077860 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -93,7 +93,7 @@ def test_concat_mismatched_categoricals_with_empty(): def test_no_tz_concat_without_copy(): # This will raise a ValueError issue if it fails # Regression test for issue 25257 - df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', + df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', tz='UTC')], }) result = pd.concat([df], copy=False) expected = df From 9a799b834b29e5de6454ee6ce30055f290ed09f3 Mon Sep 17 00:00:00 2001 From: Suraj Harjani Date: Sat, 16 May 2020 19:11:03 -0400 Subject: [PATCH 19/21] reverse changes --- pandas/tests/computation/test_eval.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 08d8d5ca342b7..7059113759759 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -727,6 +727,10 @@ def test_line_continuation(self): result = pd.eval(exp, engine=self.engine, parser=self.parser) assert result == 12 + def test_floor_expression(self): + assert pd.eval("floor(0.9 + floor(1.2+2.3))") == 3.0 + assert pd.eval("floor(1.2+2.3)") == 3.0 + def test_float_truncation(self): # GH 14241 exp = "1000000000.006" From 6699cf82a98fb4311c9ff673e778287f8237c476 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 12 Jul 2020 11:05:22 +0100 Subject: [PATCH 20/21] remove unrelated changes --- pandas/core/computation/expr.py | 21 +++++++-------------- pandas/tests/computation/test_eval.py | 4 ---- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/pandas/core/computation/expr.py b/pandas/core/computation/expr.py index a306093ee6ebf..fcccc24ed7615 100644 --- a/pandas/core/computation/expr.py +++ b/pandas/core/computation/expr.py @@ -671,26 +671,19 @@ def visit_Call(self, node, side=None, **kwargs): ) return res(*new_args) - elif isinstance(res, np.ufunc): - new_args = [self.visit(arg) for arg in node.args] - new_args = str(*new_args) - new_args = [eval(new_args)] - if node.keywords: - raise TypeError( - f'Function "{res.name}" does not support keyword arguments' - ) else: + new_args = [self.visit(arg).value for arg in node.args] - for key in node.keywords: - if not isinstance(key, ast.keyword): - raise ValueError(f"keyword error in function call '{node.func.id}'") + for key in node.keywords: + if not isinstance(key, ast.keyword): + raise ValueError(f"keyword error in function call '{node.func.id}'") - if key.arg: - kwargs[key.arg] = self.visit(key.value).value + if key.arg: + kwargs[key.arg] = self.visit(key.value).value - return self.const_type(res(*new_args, **kwargs), self.env) + return self.const_type(res(*new_args, **kwargs), self.env) def translate_In(self, op): return op diff --git a/pandas/tests/computation/test_eval.py b/pandas/tests/computation/test_eval.py index 7059113759759..08d8d5ca342b7 100644 --- a/pandas/tests/computation/test_eval.py +++ b/pandas/tests/computation/test_eval.py @@ -727,10 +727,6 @@ def test_line_continuation(self): result = pd.eval(exp, engine=self.engine, parser=self.parser) assert result == 12 - def test_floor_expression(self): - assert pd.eval("floor(0.9 + floor(1.2+2.3))") == 3.0 - assert pd.eval("floor(1.2+2.3)") == 3.0 - def test_float_truncation(self): # GH 14241 exp = "1000000000.006" From 95d551f0e5c14afd1d8c6857ae216fe052071e43 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sun, 12 Jul 2020 11:17:40 +0100 Subject: [PATCH 21/21] parametrize on copy --- pandas/tests/dtypes/test_concat.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pandas/tests/dtypes/test_concat.py b/pandas/tests/dtypes/test_concat.py index baa7882077860..5a9ad732792ea 100644 --- a/pandas/tests/dtypes/test_concat.py +++ b/pandas/tests/dtypes/test_concat.py @@ -90,11 +90,12 @@ def test_concat_mismatched_categoricals_with_empty(): tm.assert_categorical_equal(result, expected) -def test_no_tz_concat_without_copy(): - # This will raise a ValueError issue if it fails - # Regression test for issue 25257 - df = pd.DataFrame({'timestamp': [pd.Timestamp('2020-04-08 09:00:00.709949+0000', - tz='UTC')], }) - result = pd.concat([df], copy=False) - expected = df +@pytest.mark.parametrize("copy", [True, False]) +def test_concat_single_dataframe_tz_aware(copy): + # https://github.com/pandas-dev/pandas/issues/25257 + df = pd.DataFrame( + {"timestamp": [pd.Timestamp("2020-04-08 09:00:00.709949+0000", tz="UTC")]} + ) + expected = df.copy() + result = pd.concat([df], copy=copy) tm.assert_frame_equal(result, expected)