Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG accept and deprecate negative integer for max_colwidth #31569

Merged
merged 11 commits into from
Feb 2, 2020
9 changes: 9 additions & 0 deletions doc/source/whatsnew/v1.0.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -129,6 +137,7 @@ ExtensionArray
Other
^^^^^
- Regression fixed in objTOJSON.c fix return-type warning (:issue:`31463`)
- 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`)
-

.. ---------------------------------------------------------------------------
Expand Down
22 changes: 21 additions & 1 deletion pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
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,
Expand Down Expand Up @@ -341,8 +343,26 @@ 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 in future version. Instead, use None "
"to not limit the column width.",
FutureWarning,
stacklevel=4,
)

cf.register_option(
"max_colwidth", 50, max_colwidth_doc, validator=is_nonnegative_int
# FIXME: change `validator=is_nonnegative_int`
# in version 1.2
"max_colwidth",
50,
max_colwidth_doc,
validator=is_instance_factory([type(None), int]),
cb=_deprecate_negative_int_max_colwidth,
)
if is_terminal():
max_cols = 0 # automatically determine optimal number of columns
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ 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 future version 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]])
pd.reset_option("display.chop_threshold") # default None
Expand Down