Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def benchmark(n):
methods = [m for m in methods if m[0].startswith("tabulate")]

results = [(desc, timeit(code, setup_code, number=n) / n * 1e6) for desc, code in methods]
mintime = min(map(lambda x: x[1], results))
mintime = min(x[1] for x in results)
results = [(desc, t, t / mintime) for desc, t in sorted(results, key=lambda x: x[1])]
table = tabulate.tabulate(
results, ["Table formatter", "time, μs", "rel. time"], "rst", floatfmt=".1f"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ line-length = 99
exclude = ["tabulate/_version.py"]

[tool.ruff.lint]
extend-select = ["W", "ISC", "I", "C90"]
extend-select = ["W", "C4", "ISC", "I", "C90"]
ignore = ["E721", "C901"]

[tool.ruff.lint.mccabe]
Expand Down
8 changes: 4 additions & 4 deletions tabulate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):

headers = list(map(str, headers))
# rows = list(map(list, rows))
rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows))
rows = [r if _is_separating_line(r) else list(r) for r in rows]

# add or remove an index column
showindex_is_a_str = type(showindex) in [str, bytes]
Expand Down Expand Up @@ -2381,7 +2381,7 @@ def tabulate(
assert isinstance(colalign, Iterable)
if isinstance(colalign, str):
warnings.warn(
f"As a string, `colalign` is interpreted as {[c for c in colalign]}. "
f"As a string, `colalign` is interpreted as {list(colalign)}. "
f'Did you mean `colglobalalign = "{colalign}"` or `colalign = ("{colalign}",)`?',
stacklevel=2,
)
Expand Down Expand Up @@ -2423,7 +2423,7 @@ def tabulate(
assert isinstance(headersalign, Iterable)
if isinstance(headersalign, str):
warnings.warn(
f"As a string, `headersalign` is interpreted as {[c for c in headersalign]}. "
f"As a string, `headersalign` is interpreted as {list(headersalign)}. "
f'Did you mean `headersglobalalign = "{headersalign}"` '
f'or `headersalign = ("{headersalign}",)`?',
stacklevel=2,
Expand Down Expand Up @@ -2702,7 +2702,7 @@ def _update_lines(self, lines, new_line):
as add any colors from previous lines order to preserve the same formatting
as a single unwrapped string.
"""
code_matches = [x for x in _ansi_codes.finditer(new_line)]
code_matches = list(_ansi_codes.finditer(new_line))
color_codes = [code.string[code.span()[0] : code.span()[1]] for code in code_matches]

# Add color codes from earlier in the unwrapped line, and then track any new ones we add.
Expand Down
4 changes: 2 additions & 2 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ def check_warnings(func_args_kwargs, *, num=None, category=None, contain=None):
if num is not None:
assert len(W) == num
if category is not None:
assert all([issubclass(w.category, category) for w in W])
assert all(issubclass(w.category, category) for w in W)
if contain is not None:
assert all([contain in str(w.message) for w in W])
assert all(contain in str(w.message) for w in W)
2 changes: 1 addition & 1 deletion test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_numeric_column_headers():
expected = " 42\n----\n 1\n 2"
assert_equal(expected, result)

lod = [{p: i for p in range(5)} for i in range(5)]
lod = [dict.fromkeys(range(5), i) for i in range(5)]
Copy link
Copy Markdown
Contributor Author

@DimitriPapadopoulos DimitriPapadopoulos Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is more readable, but then that's the exact use case for dict.fromkeys(), added in Python 2.3.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never noticed it exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Ruff made me discover it 😄

result = tabulate(lod, "keys")
expected = "\n".join(
[
Expand Down