From fca4da006a1b328278720777bcd6ba1cb4d66fd7 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Wed, 20 Sep 2017 21:11:16 -0700 Subject: [PATCH 1/4] Fix make_signature TypeError in py3 --- pandas/tests/util/test_util.py | 10 +++++++++- pandas/util/_decorators.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pandas/tests/util/test_util.py b/pandas/tests/util/test_util.py index abd82cfa89f94..9bd30ee0217f7 100644 --- a/pandas/tests/util/test_util.py +++ b/pandas/tests/util/test_util.py @@ -9,7 +9,7 @@ import pytest from pandas.compat import intern from pandas.util._move import move_into_mutable_buffer, BadMove, stolenbuf -from pandas.util._decorators import deprecate_kwarg +from pandas.util._decorators import deprecate_kwarg, make_signature from pandas.util._validators import (validate_args, validate_kwargs, validate_args_and_kwargs, validate_bool_kwarg) @@ -467,3 +467,11 @@ def test_set_locale(self): current_locale = locale.getlocale() assert current_locale == self.current_locale + + +def test_make_signature(): + # See GH 17608 + _ = make_signature(validate_kwargs) + # Case where the func does not have default kwargs + _ = make_signature(deprecate_kwarg) + # Case where the func does have default kwargs diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index bb7ffe45c689b..1237ee67a3345 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -242,7 +242,7 @@ def make_signature(func): defaults = ('',) * n_wo_defaults else: n_wo_defaults = len(spec.args) - len(spec.defaults) - defaults = ('',) * n_wo_defaults + spec.defaults + defaults = ('',) * n_wo_defaults + tuple(spec.defaults) args = [] for i, (var, default) in enumerate(zip(spec.args, defaults)): args.append(var if default == '' else var + '=' + repr(default)) From 7cdf3b1beb394c466a2f2443609ebff6e363acd7 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 21 Sep 2017 08:01:48 -0700 Subject: [PATCH 2/4] flake8 fixup --- pandas/tests/util/test_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/util/test_util.py b/pandas/tests/util/test_util.py index 9bd30ee0217f7..95c175bcc4a3d 100644 --- a/pandas/tests/util/test_util.py +++ b/pandas/tests/util/test_util.py @@ -471,7 +471,7 @@ def test_set_locale(self): def test_make_signature(): # See GH 17608 - _ = make_signature(validate_kwargs) + make_signature(validate_kwargs) # Case where the func does not have default kwargs - _ = make_signature(deprecate_kwarg) + make_signature(deprecate_kwarg) # Case where the func does have default kwargs From 01ddac3241bfed0cd5beb6adea59350e57d61c22 Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Thu, 21 Sep 2017 12:06:36 -0700 Subject: [PATCH 3/4] rearrange per reviewer comment --- pandas/tests/util/test_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/util/test_util.py b/pandas/tests/util/test_util.py index 95c175bcc4a3d..3ba1bd3eb0826 100644 --- a/pandas/tests/util/test_util.py +++ b/pandas/tests/util/test_util.py @@ -471,7 +471,7 @@ def test_set_locale(self): def test_make_signature(): # See GH 17608 - make_signature(validate_kwargs) # Case where the func does not have default kwargs - make_signature(deprecate_kwarg) + make_signature(validate_kwargs) # Case where the func does have default kwargs + make_signature(deprecate_kwarg) From 943b3e1edfb6cee175e2aaba528a0e0b0cea977a Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Fri, 22 Sep 2017 08:39:31 -0700 Subject: [PATCH 4/4] Assertion about returned signature --- pandas/tests/util/test_util.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pandas/tests/util/test_util.py b/pandas/tests/util/test_util.py index 3ba1bd3eb0826..ffc9703abff41 100644 --- a/pandas/tests/util/test_util.py +++ b/pandas/tests/util/test_util.py @@ -472,6 +472,12 @@ def test_set_locale(self): def test_make_signature(): # See GH 17608 # Case where the func does not have default kwargs - make_signature(validate_kwargs) + sig = make_signature(validate_kwargs) + assert sig == (['fname', 'kwargs', 'compat_args'], + ['fname', 'kwargs', 'compat_args']) + # Case where the func does have default kwargs - make_signature(deprecate_kwarg) + sig = make_signature(deprecate_kwarg) + assert sig == (['old_arg_name', 'new_arg_name', + 'mapping=None', 'stacklevel=2'], + ['old_arg_name', 'new_arg_name', 'mapping', 'stacklevel'])