From c99f5156878b1b7ff4f26f07d98dbedf0cf93b69 Mon Sep 17 00:00:00 2001 From: ChrisMead Date: Wed, 1 May 2024 17:17:15 -0700 Subject: [PATCH 1/7] adding new pandas option for integer formatting --- pandas/_typing.py | 3 +- pandas/core/config_init.py | 20 ++++++-- pandas/io/formats/format.py | 42 ++++++++++++---- pandas/tests/io/formats/test_format.py | 66 ++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 13 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index f868a92554b39..c4be3fd8c23e4 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -73,7 +73,7 @@ from pandas.core.series import Series from pandas.core.window.rolling import BaseWindow - from pandas.io.formats.format import EngFormatter + from pandas.io.formats.format import EngFormatter, IntegerFormatter from pandas.tseries.holiday import AbstractHolidayCalendar ScalarLike_co = Union[ @@ -353,6 +353,7 @@ def closed(self) -> bool: ] ColspaceType = Mapping[Hashable, Union[str, int]] FloatFormatType = Union[str, Callable, "EngFormatter"] +IntegerFormatType = Union[str, Callable, "IntegerFormatter"] ColspaceArgType = Union[ str, int, Sequence[Union[str, int]], Mapping[Hashable, Union[str, int]] ] diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 46c9139c3456c..3e6defed36f34 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -276,6 +276,12 @@ def use_numba_cb(key: str) -> None: df.info() is called. Valid values True,False,'deep' """ +pc_integer_format_doc = """ +: str + This formats integer values in a DataFrame with a delimiter (either "," or "_"). The default + delimiter is no space. +""" + def table_schema_cb(key: str) -> None: from pandas.io.formats.printing import enable_data_resource_formatter @@ -388,6 +394,12 @@ def is_terminal() -> bool: cf.register_option( "max_dir_items", 100, pc_max_dir_items, validator=is_nonnegative_int ) + cf.register_option( + "integer_format", + None, + pc_integer_format_doc, + validator=is_instance_factory((type(None), str)), + ) tc_sim_interactive_doc = """ : boolean @@ -412,9 +424,11 @@ def is_terminal() -> bool: "copy_on_write", # Get the default from an environment variable, if set, otherwise defaults # to False. This environment variable can be set for testing. - "warn" - if os.environ.get("PANDAS_COPY_ON_WRITE", "0") == "warn" - else os.environ.get("PANDAS_COPY_ON_WRITE", "0") == "1", + ( + "warn" + if os.environ.get("PANDAS_COPY_ON_WRITE", "0") == "warn" + else os.environ.get("PANDAS_COPY_ON_WRITE", "0") == "1" + ), copy_on_write_doc, validator=is_one_of_factory([True, False, "warn"]), ) diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index c503121328f53..1170305048919 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -95,6 +95,7 @@ CompressionOptions, FilePath, FloatFormatType, + IntegerFormatType, FormattersType, IndexLabel, SequenceNotStr, @@ -434,6 +435,7 @@ def __init__( formatters: FormattersType | None = None, justify: str | None = None, float_format: FloatFormatType | None = None, + integer_format: IntegerFormatType | None = None, sparsify: bool | None = None, index_names: bool = True, max_rows: int | None = None, @@ -453,6 +455,7 @@ def __init__( self.formatters = self._initialize_formatters(formatters) self.justify = self._initialize_justify(justify) self.float_format = float_format + self.integer_format = integer_format self.sparsify = self._initialize_sparsify(sparsify) self.show_index_names = index_names self.decimal = decimal @@ -756,6 +759,7 @@ def format_col(self, i: int) -> list[str]: frame.iloc[:, i]._values, formatter, float_format=self.float_format, + integer_format=self.integer_format, na_rep=self.na_rep, space=self.col_space.get(frame.columns[i]), decimal=self.decimal, @@ -789,9 +793,11 @@ def _get_formatted_column_labels(self, frame: DataFrame) -> list[list[str]]: fmt_columns = columns._format_flat(include_name=False) str_columns = [ [ - " " + x - if not self._get_formatter(i) and is_numeric_dtype(dtype) - else x + ( + " " + x + if not self._get_formatter(i) and is_numeric_dtype(dtype) + else x + ) ] for i, (x, dtype) in enumerate(zip(fmt_columns, self.frame.dtypes)) ] @@ -1063,6 +1069,7 @@ def format_array( values: ArrayLike, formatter: Callable | None, float_format: FloatFormatType | None = None, + integer_format: IntegerFormatType | None = None, na_rep: str = "NaN", digits: int | None = None, space: str | int | None = None, @@ -1124,6 +1131,9 @@ def format_array( if float_format is None: float_format = get_option("display.float_format") + if integer_format is None: + integer_format = get_option("display.integer_format") + if digits is None: digits = get_option("display.precision") @@ -1132,6 +1142,7 @@ def format_array( digits=digits, na_rep=na_rep, float_format=float_format, + integer_format=integer_format, formatter=formatter, space=space, justify=justify, @@ -1153,8 +1164,10 @@ def __init__( na_rep: str = "NaN", space: str | int = 12, float_format: FloatFormatType | None = None, + integer_format: IntegerFormatType | None = None, justify: str = "right", decimal: str = ".", + delimiter: str | None = None, quoting: int | None = None, fixed_width: bool = True, leading_space: bool | None = True, @@ -1166,8 +1179,10 @@ def __init__( self.space = space self.formatter = formatter self.float_format = float_format + self.integer_format = integer_format self.justify = justify self.decimal = decimal + self.delimiter = delimiter self.quoting = quoting self.fixed_width = fixed_width self.leading_space = leading_space @@ -1455,13 +1470,22 @@ def _format_strings(self) -> list[str]: class _IntArrayFormatter(_GenericArrayFormatter): def _format_strings(self) -> list[str]: - if self.leading_space is False: - formatter_str = lambda x: f"{x:d}".format(x=x) + if ( + (self.integer_format == ",") + or (self.integer_format == "_") + or (self.integer_format == None) + ): + if self.integer_format == None: + self.integer_format = "" + if self.leading_space is False: + formatter_str = lambda x: f"{x:{self.integer_format}}".format(x=x) + else: + formatter_str = lambda x: f"{x: {self.integer_format}}".format(x=x) + formatter = self.formatter or formatter_str + fmt_values = [formatter(x) for x in self.values] + return fmt_values else: - formatter_str = lambda x: f"{x: d}".format(x=x) - formatter = self.formatter or formatter_str - fmt_values = [formatter(x) for x in self.values] - return fmt_values + raise ValueError("integer_format must be one of ',','_', or None") class _Datetime64Formatter(_GenericArrayFormatter): diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index b12cfc6876a8e..d19bf3eacc444 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2259,3 +2259,69 @@ 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()) + + +class TestIntArrayFormatter: + def test_format_comma(self): + with option_context("display.integer_format", ","): + df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + formatted_df = repr(df) + # Valid delimiter used for integer_format + expected_results = { + "A": ["1,000", "20,000", "30"], + "B": ["4.1", "50000.2", "600.0"], + } + expected_df = pd.DataFrame(expected_results) + expected_df = repr(expected_df) + + assert formatted_df == expected_df + + def test_format_underscore(self): + with option_context("display.integer_format", "_"): + df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + formatted_df = repr(df) + # Valid delimiter used for integer_format + expected_results = { + "A": ["1_000", "20_000", "30"], + "B": ["4.1", "50000.2", "600.0"], + } + expected_df = pd.DataFrame(expected_results) + expected_df = repr(expected_df) + + assert formatted_df == expected_df + + def test_format_empty(self): + with option_context("display.integer_format", None): + df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + formatted_df = repr(df) + # Valid delimiter used for integer_format + expected_results = { + "A": ["1000", "20000", "30"], + "B": ["4.1", "50000.2", "600.0"], + } + expected_df = pd.DataFrame(expected_results) + expected_df = repr(expected_df) + + assert formatted_df == expected_df + + def test_format_invalid_to_none(self): + with option_context("display.integer_format", "."): + df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + + with pytest.raises( + ValueError, match="integer_format must be one of ',','_', or None" + ): + repr(df) + + with option_context("display.integer_format", None): + df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + formatted_df = repr(df) + # Valid delimiter used for integer_format + expected_results = { + "A": ["1000", "20000", "30"], + "B": ["4.1", "50000.2", "600.0"], + } + expected_df = pd.DataFrame(expected_results) + expected_df = repr(expected_df) + + assert formatted_df == expected_df From cd120a46a40fc28b7003a73b6166be2e0efc54bb Mon Sep 17 00:00:00 2001 From: ChrisMead Date: Wed, 1 May 2024 21:03:37 -0700 Subject: [PATCH 2/7] Added whatsnew documentation and fixed PR issue --- doc/source/whatsnew/v2.2.2.rst | 5 +++++ pandas/_typing.py | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.2.2.rst b/doc/source/whatsnew/v2.2.2.rst index 0dac3660c76b2..89935121a2a54 100644 --- a/doc/source/whatsnew/v2.2.2.rst +++ b/doc/source/whatsnew/v2.2.2.rst @@ -9,6 +9,11 @@ including other versions of pandas. {{ header }} .. --------------------------------------------------------------------------- +.. _whatsnew_222.enhancements: + +Enhancements +~~~~~~~~~~~~ +- Added new display.option for intger formatting within DataFrames (:issue:`57177`) .. _whatsnew_222.regressions: Fixed regressions diff --git a/pandas/_typing.py b/pandas/_typing.py index c4be3fd8c23e4..f868a92554b39 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -73,7 +73,7 @@ from pandas.core.series import Series from pandas.core.window.rolling import BaseWindow - from pandas.io.formats.format import EngFormatter, IntegerFormatter + from pandas.io.formats.format import EngFormatter from pandas.tseries.holiday import AbstractHolidayCalendar ScalarLike_co = Union[ @@ -353,7 +353,6 @@ def closed(self) -> bool: ] ColspaceType = Mapping[Hashable, Union[str, int]] FloatFormatType = Union[str, Callable, "EngFormatter"] -IntegerFormatType = Union[str, Callable, "IntegerFormatter"] ColspaceArgType = Union[ str, int, Sequence[Union[str, int]], Mapping[Hashable, Union[str, int]] ] From bca4bdf9bd6bd9737d3410e1e895a02a459bda47 Mon Sep 17 00:00:00 2001 From: ChrisMead Date: Wed, 1 May 2024 21:09:28 -0700 Subject: [PATCH 3/7] Fixed whatsnew documentation --- doc/source/whatsnew/v2.2.2.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/source/whatsnew/v2.2.2.rst b/doc/source/whatsnew/v2.2.2.rst index 89935121a2a54..237aa4b62e8b5 100644 --- a/doc/source/whatsnew/v2.2.2.rst +++ b/doc/source/whatsnew/v2.2.2.rst @@ -14,6 +14,9 @@ including other versions of pandas. Enhancements ~~~~~~~~~~~~ - Added new display.option for intger formatting within DataFrames (:issue:`57177`) + +.. --------------------------------------------------------------------------- + .. _whatsnew_222.regressions: Fixed regressions From 7e05be7d79fa9d8c7a6bfe213af20f93c0064a35 Mon Sep 17 00:00:00 2001 From: ChrisMead Date: Thu, 2 May 2024 17:59:46 -0700 Subject: [PATCH 4/7] updated doc and removed IntegerFormatType --- doc/source/whatsnew/v2.2.2.rst | 7 ------- doc/source/whatsnew/v3.0.0.rst | 2 +- pandas/io/formats/format.py | 1 - 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/doc/source/whatsnew/v2.2.2.rst b/doc/source/whatsnew/v2.2.2.rst index 237aa4b62e8b5..b0705d7d9551f 100644 --- a/doc/source/whatsnew/v2.2.2.rst +++ b/doc/source/whatsnew/v2.2.2.rst @@ -8,13 +8,6 @@ including other versions of pandas. {{ header }} -.. --------------------------------------------------------------------------- -.. _whatsnew_222.enhancements: - -Enhancements -~~~~~~~~~~~~ -- Added new display.option for intger formatting within DataFrames (:issue:`57177`) - .. --------------------------------------------------------------------------- .. _whatsnew_222.regressions: diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 74a19472ec835..d5e9f60eb5d51 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -35,7 +35,7 @@ Other enhancements - Support passing a :class:`Series` input to :func:`json_normalize` that retains the :class:`Series` :class:`Index` (:issue:`51452`) - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) -- +- Added new display.option for intger formatting within DataFrames (:issue:`57177`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 1170305048919..4fe2be40ea144 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -95,7 +95,6 @@ CompressionOptions, FilePath, FloatFormatType, - IntegerFormatType, FormattersType, IndexLabel, SequenceNotStr, From dc15950326307ee019709ed2337284f5e9250d8f Mon Sep 17 00:00:00 2001 From: ChrisMead Date: Thu, 2 May 2024 22:17:45 -0700 Subject: [PATCH 5/7] Fixed pre-commit checks --- doc/source/whatsnew/v3.0.0.rst | 6 ------ pandas/io/formats/format.py | 8 +++----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index b0bb01407abaa..00a26b6838de4 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -39,12 +39,6 @@ Other enhancements - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) - Added new display.option for intger formatting within DataFrames (:issue:`57177`) -- :class:`.errors.DtypeWarning` improved to include column names when mixed data types are detected (:issue:`58174`) -- :meth:`DataFrame.corrwith` now accepts ``min_periods`` as optional arguments, as in :meth:`DataFrame.corr` and :meth:`Series.corr` (:issue:`9490`) -- :meth:`DataFrame.cummin`, :meth:`DataFrame.cummax`, :meth:`DataFrame.cumprod` and :meth:`DataFrame.cumsum` methods now have a ``numeric_only`` parameter (:issue:`53072`) -- :meth:`DataFrame.fillna` and :meth:`Series.fillna` can now accept ``value=None``; for non-object dtype the corresponding NA value will be used (:issue:`57723`) -- :meth:`Series.cummin` and :meth:`Series.cummax` now supports :class:`CategoricalDtype` (:issue:`52335`) -- :meth:`Series.plot` now correctly handle the ``ylabel`` parameter for pie charts, allowing for explicit control over the y-axis label (:issue:`58239`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 4fe2be40ea144..d465d0312eceb 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -434,7 +434,7 @@ def __init__( formatters: FormattersType | None = None, justify: str | None = None, float_format: FloatFormatType | None = None, - integer_format: IntegerFormatType | None = None, + integer_format: str | None = None, sparsify: bool | None = None, index_names: bool = True, max_rows: int | None = None, @@ -1068,7 +1068,7 @@ def format_array( values: ArrayLike, formatter: Callable | None, float_format: FloatFormatType | None = None, - integer_format: IntegerFormatType | None = None, + integer_format: str | None = None, na_rep: str = "NaN", digits: int | None = None, space: str | int | None = None, @@ -1163,10 +1163,9 @@ def __init__( na_rep: str = "NaN", space: str | int = 12, float_format: FloatFormatType | None = None, - integer_format: IntegerFormatType | None = None, + integer_format: str | None = None, justify: str = "right", decimal: str = ".", - delimiter: str | None = None, quoting: int | None = None, fixed_width: bool = True, leading_space: bool | None = True, @@ -1181,7 +1180,6 @@ def __init__( self.integer_format = integer_format self.justify = justify self.decimal = decimal - self.delimiter = delimiter self.quoting = quoting self.fixed_width = fixed_width self.leading_space = leading_space From 5fdae46b95b6dc0747db4097f6c7852e0149add3 Mon Sep 17 00:00:00 2001 From: ChrisMead Date: Thu, 2 May 2024 22:37:20 -0700 Subject: [PATCH 6/7] Fixed more pre-commit issues --- doc/source/whatsnew/v3.0.0.rst | 2 +- pandas/core/config_init.py | 4 ++-- pandas/io/formats/format.py | 9 +++------ pandas/tests/io/formats/test_format.py | 16 ++++++++-------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 00a26b6838de4..4a6606ed20df2 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -38,7 +38,7 @@ Other enhancements - Support reading value labels from Stata 108-format (Stata 6) and earlier files (:issue:`58154`) - Users can globally disable any ``PerformanceWarning`` by setting the option ``mode.performance_warnings`` to ``False`` (:issue:`56920`) - :meth:`Styler.format_index_names` can now be used to format the index and column names (:issue:`48936` and :issue:`47489`) -- Added new display.option for intger formatting within DataFrames (:issue:`57177`) +- Added new display.option for integer formatting within DataFrames (:issue:`57177`) .. --------------------------------------------------------------------------- .. _whatsnew_300.notable_bug_fixes: diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 3e6defed36f34..1e651e6506bee 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -278,8 +278,8 @@ def use_numba_cb(key: str) -> None: pc_integer_format_doc = """ : str - This formats integer values in a DataFrame with a delimiter (either "," or "_"). The default - delimiter is no space. + This formats integer values in a DataFrame with a delimiter that defaults + to None (''). The other two options are 'comma' (',') and 'underscore' ('_'). """ diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index d465d0312eceb..2c914b2028bdc 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -1467,12 +1467,9 @@ def _format_strings(self) -> list[str]: class _IntArrayFormatter(_GenericArrayFormatter): def _format_strings(self) -> list[str]: - if ( - (self.integer_format == ",") - or (self.integer_format == "_") - or (self.integer_format == None) - ): - if self.integer_format == None: + + if self.integer_format in (",", "_", None): + if self.integer_format is None: self.integer_format = "" if self.leading_space is False: formatter_str = lambda x: f"{x:{self.integer_format}}".format(x=x) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index d19bf3eacc444..7797e37778b2d 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2264,42 +2264,42 @@ def test_filepath_or_buffer_bad_arg_raises(float_frame, method): class TestIntArrayFormatter: def test_format_comma(self): with option_context("display.integer_format", ","): - df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + df = DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) formatted_df = repr(df) # Valid delimiter used for integer_format expected_results = { "A": ["1,000", "20,000", "30"], "B": ["4.1", "50000.2", "600.0"], } - expected_df = pd.DataFrame(expected_results) + expected_df = DataFrame(expected_results) expected_df = repr(expected_df) assert formatted_df == expected_df def test_format_underscore(self): with option_context("display.integer_format", "_"): - df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + df = DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) formatted_df = repr(df) # Valid delimiter used for integer_format expected_results = { "A": ["1_000", "20_000", "30"], "B": ["4.1", "50000.2", "600.0"], } - expected_df = pd.DataFrame(expected_results) + expected_df = DataFrame(expected_results) expected_df = repr(expected_df) assert formatted_df == expected_df def test_format_empty(self): with option_context("display.integer_format", None): - df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + df = DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) formatted_df = repr(df) # Valid delimiter used for integer_format expected_results = { "A": ["1000", "20000", "30"], "B": ["4.1", "50000.2", "600.0"], } - expected_df = pd.DataFrame(expected_results) + expected_df = DataFrame(expected_results) expected_df = repr(expected_df) assert formatted_df == expected_df @@ -2314,14 +2314,14 @@ def test_format_invalid_to_none(self): repr(df) with option_context("display.integer_format", None): - df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + df = DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) formatted_df = repr(df) # Valid delimiter used for integer_format expected_results = { "A": ["1000", "20000", "30"], "B": ["4.1", "50000.2", "600.0"], } - expected_df = pd.DataFrame(expected_results) + expected_df = DataFrame(expected_results) expected_df = repr(expected_df) assert formatted_df == expected_df From 7c041c79b9a523584b7fcb4e5bda3401ab7ff943 Mon Sep 17 00:00:00 2001 From: ChrisMead Date: Thu, 2 May 2024 22:42:00 -0700 Subject: [PATCH 7/7] fixing precommit issues --- pandas/core/config_init.py | 2 +- pandas/tests/io/formats/test_format.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 1e651e6506bee..38138ce9c663c 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -279,7 +279,7 @@ def use_numba_cb(key: str) -> None: pc_integer_format_doc = """ : str This formats integer values in a DataFrame with a delimiter that defaults - to None (''). The other two options are 'comma' (',') and 'underscore' ('_'). + to None (''). The other two options are 'comma' (',') and 'underscore' ('_'). """ diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 7797e37778b2d..07c8bb06f6d75 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -2306,7 +2306,7 @@ def test_format_empty(self): def test_format_invalid_to_none(self): with option_context("display.integer_format", "."): - df = pd.DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) + df = DataFrame({"A": [1000, 20000, 30], "B": [4.1, 50000.2, 600.0]}) with pytest.raises( ValueError, match="integer_format must be one of ',','_', or None"