Skip to content

Commit

Permalink
DEPR: display.column_space (pandas-dev#47280)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and yehoshuadimarsky committed Jul 13, 2022
1 parent aba825a commit 0b28f0a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,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`)
-

.. ---------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion pandas/core/config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions pandas/io/formats/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_repr_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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)

0 comments on commit 0b28f0a

Please sign in to comment.