Skip to content

Commit b6f4961

Browse files
committed
truncate based on message length rather than number of columns
1 parent 72faba9 commit b6f4961

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pandas/core/col.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,21 @@ def wrapper(*args: Any, **kwargs: Any) -> Expression:
222222

223223
def col(col_name: Hashable) -> Expression:
224224
"""
225-
Generate deferred object representing a column of a `DataFrame`.
225+
Generate deferred object representing a column of a DataFrame.
226226
227227
Any place which accepts ``lambda df: df[col_name]``, such as
228228
:meth:`DataFrame.assign` or :meth:`DataFrame.loc`, can also accept
229229
``pd.col(col_name)``.
230230
231-
Arguments
232-
---------
231+
Parameters
232+
----------
233233
col_name : Hashable
234234
Column name.
235235
236236
Returns
237237
-------
238238
`pandas.api.typing.Expression`
239+
A deferred object representing a column of a DataFrame.
239240
240241
Examples
241242
--------
@@ -260,15 +261,14 @@ def col(col_name: Hashable) -> Expression:
260261

261262
def func(df: DataFrame) -> Series:
262263
if col_name not in df.columns:
263-
columns_list = df.columns.tolist()
264-
max_cols = 10
265-
if len(columns_list) > max_cols:
266-
columns_hint = columns_list[:max_cols] + ["..."]
267-
else:
268-
columns_hint = columns_list
264+
columns_str = str(df.columns.tolist())
265+
max_len = 90
266+
if len(columns_str) > max_len:
267+
columns_str = columns_str[:max_len] + "...]"
268+
269269
msg = (
270270
f"Column '{col_name}' not found in given DataFrame.\n\n"
271-
f"Hint: did you mean one of {columns_hint} instead?"
271+
f"Hint: did you mean one of {columns_str} instead?"
272272
)
273273
raise ValueError(msg)
274274
return df[col_name]

pandas/tests/test_col.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_invalid() -> None:
7575
"did you mean one of "
7676
r"\['col_0', 'col_1', 'col_2', 'col_3', "
7777
"'col_4', 'col_5', 'col_6', 'col_7', "
78-
r"'col_8', 'col_9', '\.\.\.'\] instead"
78+
r"'col_8', 'col_9',\.\.\.\] instead"
7979
)
8080
""
8181
with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)