From 9954a1b25be6e19dc9aab3e70acdbc2699636f77 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:55:05 -0700 Subject: [PATCH] DEPR: Configuration options --- doc/source/whatsnew/v2.0.0.rst | 2 ++ pandas/core/config_init.py | 29 +------------------------- pandas/tests/io/formats/test_format.py | 15 +++++-------- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 1050eed40fbb4..e54f08dd44361 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -224,6 +224,8 @@ Removal of prior version deprecations/changes - Enforced disallowing a string column label into ``times`` in :meth:`DataFrame.ewm` (:issue:`43265`) - Removed setting Categorical._codes directly (:issue:`41429`) - Enforced :meth:`Rolling.count` with ``min_periods=None`` to default to the size of the window (:issue:`31302`) +- Enforced the ``display.max_colwidth`` option to not accept negative integers (:issue:`31569`) +- Removed the ``display.column_space`` option in favor of ``df.to_string(col_space=...)`` (:issue:`47280`) - Removed the deprecated method ``mad`` from pandas classes (:issue:`11787`) - Removed the deprecated method ``tshift`` from pandas classes (:issue:`11631`) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 378f9dc80bb6d..e6bdbbcb5aa12 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -13,7 +13,6 @@ import os from typing import Callable -import warnings import pandas._config.config as cf from pandas._config.config import ( @@ -27,8 +26,6 @@ is_text, ) -from pandas.util._exceptions import find_stack_level - # compute use_bottleneck_doc = """ @@ -363,17 +360,6 @@ def is_terminal() -> bool: float_format_doc, validator=is_one_of_factory([None, is_callable]), ) - - def _deprecate_column_space(key) -> None: - warnings.warn( - "column_space is deprecated and will be removed " - "in a future version. Use df.to_string(col_space=...) " - "instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - - cf.register_option("column_space", 12, validator=is_int, cb=_deprecate_column_space) cf.register_option( "max_info_rows", 1690785, @@ -389,24 +375,11 @@ def _deprecate_column_space(key) -> None: ) cf.register_option("max_categories", 8, pc_max_categories_doc, validator=is_int) - def _deprecate_negative_int_max_colwidth(key) -> None: - 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 in future version. Instead, use None " - "to not limit the column width.", - FutureWarning, - stacklevel=find_stack_level(), - ) - cf.register_option( - # TODO(2.0): change `validator=is_nonnegative_int` see GH#31569 "max_colwidth", 50, max_colwidth_doc, - validator=is_instance_factory([type(None), int]), - cb=_deprecate_negative_int_max_colwidth, + validator=is_nonnegative_int, ) 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 0b3f6395e51d7..b3e2e81e95613 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -252,12 +252,13 @@ 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): - # TODO(2.0): remove in future version after deprecation cycle - # Non-regression test for: + def test_max_colwidth_negative_int_raises(self): + # Deprecation enforced from: # https://github.com/pandas-dev/pandas/issues/31532 width = get_option("display.max_colwidth") - with tm.assert_produces_warning(FutureWarning): + with pytest.raises( + ValueError, match="Value must be a nonnegative integer or None" + ): set_option("display.max_colwidth", -1) set_option("display.max_colwidth", width) @@ -3483,9 +3484,3 @@ def test_filepath_or_buffer_bad_arg_raises(float_frame, method): msg = "buf is not a file name and it has no write method" with pytest.raises(TypeError, match=msg): getattr(float_frame, method)(buf=object()) - - -def test_col_space_deprecated(): - # GH 7576 - with tm.assert_produces_warning(FutureWarning, match="column_space is"): - set_option("display.column_space", 11)