From dfff16c15a336f2f18929f1ceaed26d36ec5d2bd Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 12:42:38 +0100 Subject: [PATCH 01/10] BUG accept and deprecate negative integer for max_colwidth --- pandas/core/config_init.py | 16 +++++++++++++++- pandas/tests/io/formats/test_format.py | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 3776c6f816d96..c9e56accd4755 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -9,6 +9,7 @@ module is imported, register them here rather than in the module. """ +import warnings import pandas._config.config as cf from pandas._config.config import ( is_bool, @@ -341,8 +342,21 @@ def is_terminal() -> bool: validator=is_instance_factory([type(None), int]), ) cf.register_option("max_categories", 8, pc_max_categories_doc, validator=is_int) + + def _deprecate_negative_int_max_colwidth(key): + value = cf.get_option(key) + if value is not None and value < 0: + warnings.warn( + "Passing a negative integer is deprecated in version 1.0 and " + "will not be supported from version 1.2. Instead, use None to " + "not limit the column width.", FutureWarning + ) + cf.register_option( - "max_colwidth", 50, max_colwidth_doc, validator=is_nonnegative_int + # FIXME: change `validator=is_int` to `validator=is_nonnegative_int` + # in version 1.2 + "max_colwidth", 50, max_colwidth_doc, validator=is_int, + cb=_deprecate_negative_int_max_colwidth ) if is_terminal(): max_cols = 0 # automatically determine optimal number of columns diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 7650561d3072d..a74d0833b2f5f 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -239,6 +239,16 @@ def test_repr_truncation(self): with option_context("display.max_colwidth", max_len + 2): assert "..." not in repr(df) + def test_repr_deprecation_negative_int(self): + # FIXME: remove in version 1.2 after deprecation cycle + # Non-regression test for: + # https://github.com/pandas-dev/pandas/issues/31532 + with pytest.warns(FutureWarning) as records: + set_option("display.max_colwidth", -1) + assert len(records) == 1 + assert ("Instead, use None to not limit the column width." in + records[0].message.args[0]) + def test_repr_chop_threshold(self): df = DataFrame([[0.1, 0.5], [0.5, -0.1]]) pd.reset_option("display.chop_threshold") # default None From f1bb21533279b4c68c127dd2ceaea0f900d52145 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 12:49:24 +0100 Subject: [PATCH 02/10] blurp --- pandas/core/config_init.py | 10 +++++++--- pandas/tests/io/formats/test_format.py | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index c9e56accd4755..d5966a959dcd1 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -349,14 +349,18 @@ def _deprecate_negative_int_max_colwidth(key): warnings.warn( "Passing a negative integer is deprecated in version 1.0 and " "will not be supported from version 1.2. Instead, use None to " - "not limit the column width.", FutureWarning + "not limit the column width.", + FutureWarning, ) cf.register_option( # FIXME: change `validator=is_int` to `validator=is_nonnegative_int` # in version 1.2 - "max_colwidth", 50, max_colwidth_doc, validator=is_int, - cb=_deprecate_negative_int_max_colwidth + "max_colwidth", + 50, + max_colwidth_doc, + validator=is_int, + cb=_deprecate_negative_int_max_colwidth, ) if is_terminal(): max_cols = 0 # automatically determine optimal number of columns diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index a74d0833b2f5f..02df53958c750 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -246,8 +246,10 @@ def test_repr_deprecation_negative_int(self): with pytest.warns(FutureWarning) as records: set_option("display.max_colwidth", -1) assert len(records) == 1 - assert ("Instead, use None to not limit the column width." in - records[0].message.args[0]) + assert ( + "Instead, use None to not limit the column width." + in records[0].message.args[0] + ) def test_repr_chop_threshold(self): df = DataFrame([[0.1, 0.5], [0.5, -0.1]]) From aebabb597643a795f7aae4538a9f91d4dbf94728 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 12:54:25 +0100 Subject: [PATCH 03/10] add whats new --- doc/source/whatsnew/v1.0.1.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.0.1.rst b/doc/source/whatsnew/v1.0.1.rst index 801d97b777e00..32355349ff2ef 100644 --- a/doc/source/whatsnew/v1.0.1.rst +++ b/doc/source/whatsnew/v1.0.1.rst @@ -128,7 +128,7 @@ ExtensionArray Other ^^^^^ -- +- Fixed a regression where setting ``display.max_colwidth`` was not accepting negative integer. In addition, this behavior has been deprecated in favor of using ``None`` (:issue:`31532`) - .. --------------------------------------------------------------------------- From e64c5ea24cc813f7baaef9671d8a10b677cfada4 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 13:23:51 +0100 Subject: [PATCH 04/10] use assert_produces_warning and set stacklevel --- pandas/core/config_init.py | 1 + pandas/tests/io/formats/test_format.py | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index d5966a959dcd1..38d6837ccff27 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -351,6 +351,7 @@ def _deprecate_negative_int_max_colwidth(key): "will not be supported from version 1.2. Instead, use None to " "not limit the column width.", FutureWarning, + stacklevel=4, ) cf.register_option( diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 02df53958c750..e9891b87c551c 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -243,13 +243,8 @@ def test_repr_deprecation_negative_int(self): # FIXME: remove in version 1.2 after deprecation cycle # Non-regression test for: # https://github.com/pandas-dev/pandas/issues/31532 - with pytest.warns(FutureWarning) as records: + with tm.assert_produces_warning(FutureWarning): set_option("display.max_colwidth", -1) - assert len(records) == 1 - assert ( - "Instead, use None to not limit the column width." - in records[0].message.args[0] - ) def test_repr_chop_threshold(self): df = DataFrame([[0.1, 0.5], [0.5, -0.1]]) From 2ed4539e82832c1201472533f3e148982c30ce52 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 13:51:37 +0100 Subject: [PATCH 05/10] reset_option --- pandas/tests/io/formats/test_format.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index e9891b87c551c..f1fcc3e0e61e1 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -243,8 +243,10 @@ def test_repr_deprecation_negative_int(self): # FIXME: remove in version 1.2 after deprecation cycle # Non-regression test for: # https://github.com/pandas-dev/pandas/issues/31532 + value = get_option("display.max_colwidth") with tm.assert_produces_warning(FutureWarning): set_option("display.max_colwidth", -1) + set_option("display.max_colwidth", value) def test_repr_chop_threshold(self): df = DataFrame([[0.1, 0.5], [0.5, -0.1]]) From 85a0308997c2b17608fbee7338f38c8cc4bd63f0 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 13:57:26 +0100 Subject: [PATCH 06/10] accept none --- pandas/core/config_init.py | 2 +- pandas/tests/io/formats/test_format.py | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 38d6837ccff27..08951849281fc 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -360,7 +360,7 @@ def _deprecate_negative_int_max_colwidth(key): "max_colwidth", 50, max_colwidth_doc, - validator=is_int, + validator=is_instance_factory([type(None), int]), cb=_deprecate_negative_int_max_colwidth, ) if is_terminal(): diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index f1fcc3e0e61e1..e9891b87c551c 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -243,10 +243,8 @@ def test_repr_deprecation_negative_int(self): # FIXME: remove in version 1.2 after deprecation cycle # Non-regression test for: # https://github.com/pandas-dev/pandas/issues/31532 - value = get_option("display.max_colwidth") with tm.assert_produces_warning(FutureWarning): set_option("display.max_colwidth", -1) - set_option("display.max_colwidth", value) def test_repr_chop_threshold(self): df = DataFrame([[0.1, 0.5], [0.5, -0.1]]) From 24da3896ea17fa43b0d7989c3ecc6f0047288a40 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 14:03:42 +0100 Subject: [PATCH 07/10] update comment --- pandas/core/config_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 08951849281fc..febb9339ec254 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -355,7 +355,7 @@ def _deprecate_negative_int_max_colwidth(key): ) cf.register_option( - # FIXME: change `validator=is_int` to `validator=is_nonnegative_int` + # FIXME: change `validator=is_nonnegative_int` # in version 1.2 "max_colwidth", 50, From 6bc14002c5ecc8f1105aa90698dd7ae3a015c497 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 14:26:25 +0100 Subject: [PATCH 08/10] iter --- pandas/tests/io/formats/test_format.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index e9891b87c551c..3cafd1a6f00dc 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -243,8 +243,10 @@ def test_repr_deprecation_negative_int(self): # FIXME: remove in version 1.2 after deprecation cycle # Non-regression test for: # https://github.com/pandas-dev/pandas/issues/31532 + width = get_option("display.max_colwidth") with tm.assert_produces_warning(FutureWarning): set_option("display.max_colwidth", -1) + set_option("display.max_colwidth", width) def test_repr_chop_threshold(self): df = DataFrame([[0.1, 0.5], [0.5, -0.1]]) From 6ea241582e60f90bc594868f4990885243563418 Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 14:53:58 +0100 Subject: [PATCH 09/10] add line break --- pandas/core/config_init.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index febb9339ec254..209c521d95a8b 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -10,6 +10,7 @@ """ import warnings + import pandas._config.config as cf from pandas._config.config import ( is_bool, From e87e237b8dc38df2659ac437f8492f95279b612b Mon Sep 17 00:00:00 2001 From: Guillaume Lemaitre Date: Sun, 2 Feb 2020 18:15:54 +0100 Subject: [PATCH 10/10] address comments --- doc/source/whatsnew/v1.0.1.rst | 10 +++++++++- pandas/core/config_init.py | 4 ++-- pandas/tests/io/formats/test_format.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/source/whatsnew/v1.0.1.rst b/doc/source/whatsnew/v1.0.1.rst index 32355349ff2ef..baaf9e3fae5b4 100644 --- a/doc/source/whatsnew/v1.0.1.rst +++ b/doc/source/whatsnew/v1.0.1.rst @@ -10,6 +10,14 @@ including other versions of pandas. .. --------------------------------------------------------------------------- +.. _whatsnew_101.deprecations: + +Deprecations +~~~~~~~~~~~~ + +- Support for negative integer for :attr:`pd.options.display.max_colwidth` is deprecated in favor of using ``None`` (:issue:`31532`) + +.. --------------------------------------------------------------------------- .. _whatsnew_101.bug_fixes: @@ -128,7 +136,7 @@ ExtensionArray Other ^^^^^ -- Fixed a regression where setting ``display.max_colwidth`` was not accepting negative integer. In addition, this behavior has been deprecated in favor of using ``None`` (:issue:`31532`) +- Fixed a regression where setting :attr:`pd.options.display.max_colwidth` was not accepting negative integer. In addition, this behavior has been deprecated in favor of using ``None`` (:issue:`31532`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 209c521d95a8b..b0410e31c6de7 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -349,8 +349,8 @@ def _deprecate_negative_int_max_colwidth(key): if value is not None and value < 0: warnings.warn( "Passing a negative integer is deprecated in version 1.0 and " - "will not be supported from version 1.2. Instead, use None to " - "not limit the column width.", + "will not be supported in future version. Instead, use None " + "to not limit the column width.", FutureWarning, stacklevel=4, ) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 3cafd1a6f00dc..bf7b98eb78f11 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -240,7 +240,7 @@ def test_repr_truncation(self): assert "..." not in repr(df) def test_repr_deprecation_negative_int(self): - # FIXME: remove in version 1.2 after deprecation cycle + # FIXME: remove in future version after deprecation cycle # Non-regression test for: # https://github.com/pandas-dev/pandas/issues/31532 width = get_option("display.max_colwidth")