From e14a9bd41d8cd8ac52c5c958b735623fe0eae064 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Wed, 28 Feb 2024 17:21:32 -0500 Subject: [PATCH] ENH: Report how far off the formatting is (#57667) --- pandas/io/excel/_base.py | 3 ++- pandas/tests/io/excel/test_writers.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 6fa23ef94d200..8a287beac7afd 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1327,7 +1327,8 @@ def _value_with_fmt( # xref https://support.microsoft.com/en-au/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3 if len(val) > 32767: warnings.warn( - "Cell contents too long, truncated to 32767 characters", + f"Cell contents too long ({len(val)}), " + "truncated to 32767 characters", UserWarning, stacklevel=find_stack_level(), ) diff --git a/pandas/tests/io/excel/test_writers.py b/pandas/tests/io/excel/test_writers.py index ca5c98f49f09c..6637b4f931102 100644 --- a/pandas/tests/io/excel/test_writers.py +++ b/pandas/tests/io/excel/test_writers.py @@ -1390,7 +1390,7 @@ def test_to_excel_empty_frame(self, engine, tmp_excel): def test_to_excel_raising_warning_when_cell_character_exceed_limit(self): # GH#56954 df = DataFrame({"A": ["a" * 32768]}) - msg = "Cell contents too long, truncated to 32767 characters" + msg = r"Cell contents too long \(32768\), truncated to 32767 characters" with tm.assert_produces_warning( UserWarning, match=msg, raise_on_extra_warnings=False ):