diff --git a/doc/source/whatsnew/v1.5.0.rst b/doc/source/whatsnew/v1.5.0.rst index 8a947e4505ec5..66f5ea11f87ff 100644 --- a/doc/source/whatsnew/v1.5.0.rst +++ b/doc/source/whatsnew/v1.5.0.rst @@ -686,6 +686,7 @@ Other Deprecations - Deprecated the ``closed`` argument in :class:`intervaltree` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`) - Deprecated the ``closed`` argument in :class:`ArrowInterval` in favor of ``inclusive`` argument; In a future version passing ``closed`` will raise (:issue:`40245`) - Deprecated allowing ``unit="M"`` or ``unit="Y"`` in :class:`Timestamp` constructor with a non-round float value (:issue:`47267`) +- Deprecated the ``display.column_space`` global configuration option (:issue:`7576`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index dd106b6dbb63c..47cf64ba24022 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -361,7 +361,17 @@ def is_terminal() -> bool: float_format_doc, validator=is_one_of_factory([None, is_callable]), ) - cf.register_option("column_space", 12, validator=is_int) + + def _deprecate_column_space(key): + 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, diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 3019aa1fc2dc7..045e74c1b6083 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1294,7 +1294,7 @@ def format_array( fmt_klass = GenericArrayFormatter if space is None: - space = get_option("display.column_space") + space = 12 if float_format is None: float_format = get_option("display.float_format") @@ -2099,7 +2099,6 @@ def set_eng_float_format(accuracy: int = 3, use_eng_prefix: bool = False) -> Non See also EngFormatter. """ set_option("display.float_format", EngFormatter(accuracy, use_eng_prefix)) - set_option("display.column_space", max(12, accuracy + 9)) def get_level_lengths( diff --git a/pandas/tests/frame/test_repr_info.py b/pandas/tests/frame/test_repr_info.py index 765640c94673e..f42660b297cb0 100644 --- a/pandas/tests/frame/test_repr_info.py +++ b/pandas/tests/frame/test_repr_info.py @@ -219,7 +219,7 @@ def test_repr_unsortable(self, float_frame): ) repr(unsortable) - fmt.set_option("display.precision", 3, "display.column_space", 10) + fmt.set_option("display.precision", 3) repr(float_frame) fmt.set_option("display.max_rows", 10, "display.max_columns", 2) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 04f4b0a313fdc..a7c9c86b3d9a5 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -1442,8 +1442,6 @@ def test_to_string_float_formatting(self): fmt.set_option( "display.precision", 5, - "display.column_space", - 12, "display.notebook_repr_html", False, ) @@ -3402,3 +3400,9 @@ 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)