flexablelib 2.0.21__tar.gz → 2.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flexablelib-2.0.21 → flexablelib-2.1.0}/CHANGELOG.md +13 -0
- {flexablelib-2.0.21/flexablelib.egg-info → flexablelib-2.1.0}/PKG-INFO +10 -1
- {flexablelib-2.0.21 → flexablelib-2.1.0}/README.md +9 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/table.py +67 -3
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/writers.py +2 -5
- {flexablelib-2.0.21 → flexablelib-2.1.0/flexablelib.egg-info}/PKG-INFO +10 -1
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib.egg-info/SOURCES.txt +1 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/package.json +1 -1
- flexablelib-2.1.0/tests/test_v210_rows_copy.py +94 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/LICENSE +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/MANIFEST.in +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/__init__.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/_speedups.c +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/_width_tables.h +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/cells.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/colors.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/columns.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/fast.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/merges.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/options.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/py.typed +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/readers.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/style_compositions.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/table_strings.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/text_width.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib/utils.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib.egg-info/dependency_links.txt +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib.egg-info/requires.txt +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/flexablelib.egg-info/top_level.txt +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/pytest.ini +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/setup.cfg +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/setup.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/style_examples.md +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/conftest.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/helpers.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_cells.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_columns.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_excel.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_features.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_issues.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_merge_edge_matrix.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_merges.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_readme_examples.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_style_line_widths.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_styles.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_text_width.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_two_pass_measurement.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_upstream_issues.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v2021_fixes.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v2110_fixes.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v213_features.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v214_features.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v215_features.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v216_features.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v217_features.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v218_features.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v219_coverage.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tests/test_v219_fixes.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tools/benchmark.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tools/generate_width_tables.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tools/readme_gallery.py +0 -0
- {flexablelib-2.0.21 → flexablelib-2.1.0}/tools/text_to_png.py +0 -0
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [2.1.0] - 2026-11-03
|
|
6
|
+
|
|
7
|
+
### Changed (breaking)
|
|
8
|
+
- ``Table.rows`` returns a copy (new outer list and new row lists) with
|
|
9
|
+
``None`` in empty or missing cells, the same values ``to_records`` gives;
|
|
10
|
+
editing it no longer changes the table. Code that edited ``t.rows`` in place
|
|
11
|
+
should use ``add_row`` and the new ``set_cell(row, column, value)``.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- ``Table.set_cell(row, column, value)``: replace one cell by row position and
|
|
15
|
+
column position or header (``table.missing`` empties it). It keeps the row
|
|
16
|
+
and column stores in sync, which editing ``t.rows`` never did.
|
|
17
|
+
|
|
5
18
|
## [2.0.21] - 2026-11-03
|
|
6
19
|
|
|
7
20
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: Fast, dependency-free terminal tables for Python: 56 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -439,6 +439,15 @@ table.parse_str_numbers = True
|
|
|
439
439
|
|
|
440
440
|
Values with leading zeros are left alone, so `'007'` stays a string.
|
|
441
441
|
|
|
442
|
+
`table.rows` is a copy of the data, with `None` in empty cells (the same values
|
|
443
|
+
as `to_records()`), so editing it does not change the table. Use `add_row` and
|
|
444
|
+
`set_cell` instead:
|
|
445
|
+
|
|
446
|
+
```python
|
|
447
|
+
table.set_cell(0, 'Uptime', 98.2) # row position, column position or header
|
|
448
|
+
table.set_cell(1, 2, table.missing) # empty a cell
|
|
449
|
+
```
|
|
450
|
+
|
|
442
451
|
## Merging cells
|
|
443
452
|
|
|
444
453
|
Render a rectangular block as a single cell, across columns, down rows, or
|
|
@@ -374,6 +374,15 @@ table.parse_str_numbers = True
|
|
|
374
374
|
|
|
375
375
|
Values with leading zeros are left alone, so `'007'` stays a string.
|
|
376
376
|
|
|
377
|
+
`table.rows` is a copy of the data, with `None` in empty cells (the same values
|
|
378
|
+
as `to_records()`), so editing it does not change the table. Use `add_row` and
|
|
379
|
+
`set_cell` instead:
|
|
380
|
+
|
|
381
|
+
```python
|
|
382
|
+
table.set_cell(0, 'Uptime', 98.2) # row position, column position or header
|
|
383
|
+
table.set_cell(1, 2, table.missing) # empty a cell
|
|
384
|
+
```
|
|
385
|
+
|
|
377
386
|
## Merging cells
|
|
378
387
|
|
|
379
388
|
Render a rectangular block as a single cell, across columns, down rows, or
|
|
@@ -1153,9 +1153,22 @@ class Table(object):
|
|
|
1153
1153
|
@property
|
|
1154
1154
|
def rows(self) -> List[list]:
|
|
1155
1155
|
"""
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1156
|
+
A copy of the table's data as rows.
|
|
1157
|
+
|
|
1158
|
+
Each call returns a new outer list with new row lists, so changing it
|
|
1159
|
+
never changes the table; use :meth:`add_row` and :meth:`set_cell` for
|
|
1160
|
+
that. Empty or missing cells come back as ``None``, the same value
|
|
1161
|
+
:meth:`to_records` and the exports use.
|
|
1162
|
+
"""
|
|
1163
|
+
width = len(self.__headers)
|
|
1164
|
+
copied = []
|
|
1165
|
+
for row in self.__rows:
|
|
1166
|
+
values = [None if isinstance(cell, ValuePlacer) else cell
|
|
1167
|
+
for cell in row]
|
|
1168
|
+
if len(values) < width:
|
|
1169
|
+
values.extend([None] * (width - len(values)))
|
|
1170
|
+
copied.append(values)
|
|
1171
|
+
return copied
|
|
1159
1172
|
|
|
1160
1173
|
@property
|
|
1161
1174
|
def internal_rows(self) -> List[list]:
|
|
@@ -3334,6 +3347,57 @@ class Table(object):
|
|
|
3334
3347
|
self.__transpose_row_to_columns(data)
|
|
3335
3348
|
self.__adjust_columns_to_row_count(rows_added_before=True)
|
|
3336
3349
|
|
|
3350
|
+
def set_cell(self, row: int, column: Union[int, str], value) -> None:
|
|
3351
|
+
"""
|
|
3352
|
+
Replace the value of one cell.
|
|
3353
|
+
|
|
3354
|
+
``row`` is the row position (negative counts from the end) and
|
|
3355
|
+
``column`` is the column position or its header. Pass
|
|
3356
|
+
:attr:`missing` to empty the cell.
|
|
3357
|
+
|
|
3358
|
+
Example::
|
|
3359
|
+
|
|
3360
|
+
table = Table(rows=[['api', 99.9]], headers=['Service', 'Uptime'])
|
|
3361
|
+
table.set_cell(0, 'Uptime', 98.2)
|
|
3362
|
+
"""
|
|
3363
|
+
if isinstance(row, bool) or not isinstance(row, int):
|
|
3364
|
+
raise TypeError(
|
|
3365
|
+
f'set_cell: row must be an int, got {type(row).__name__}'
|
|
3366
|
+
)
|
|
3367
|
+
row_count = len(self.__rows)
|
|
3368
|
+
if not -row_count <= row < row_count:
|
|
3369
|
+
raise IndexError(
|
|
3370
|
+
f'set_cell: row {row} out of range for {row_count} rows'
|
|
3371
|
+
)
|
|
3372
|
+
row %= row_count
|
|
3373
|
+
if isinstance(column, str):
|
|
3374
|
+
if column not in self.__headers:
|
|
3375
|
+
raise KeyError(f'set_cell: no column named {column!r}')
|
|
3376
|
+
column_i = self.__headers.index(column)
|
|
3377
|
+
elif isinstance(column, bool) or not isinstance(column, int):
|
|
3378
|
+
raise TypeError(
|
|
3379
|
+
'set_cell: column must be an int or a header, '
|
|
3380
|
+
f'got {type(column).__name__}'
|
|
3381
|
+
)
|
|
3382
|
+
else:
|
|
3383
|
+
column_count = len(self.__headers)
|
|
3384
|
+
if not -column_count <= column < column_count:
|
|
3385
|
+
raise IndexError(
|
|
3386
|
+
f'set_cell: column {column} out of range for '
|
|
3387
|
+
f'{column_count} columns'
|
|
3388
|
+
)
|
|
3389
|
+
column_i = column % column_count
|
|
3390
|
+
if self.__parse_str_numbers and isinstance(value, str):
|
|
3391
|
+
from .readers import parse_value
|
|
3392
|
+
value = parse_value(value, True)
|
|
3393
|
+
header = self.__headers[column_i]
|
|
3394
|
+
# Both orientations hold the same data and both are read while
|
|
3395
|
+
# rendering, so all four stores change together.
|
|
3396
|
+
self.__rows[row][column_i] = value
|
|
3397
|
+
self.__rows_with_i[row][column_i + 1] = value
|
|
3398
|
+
self.__columns[header][row] = value
|
|
3399
|
+
self.__columns_with_i[header][row] = value
|
|
3400
|
+
|
|
3337
3401
|
def __adjust_headers_to_data_length(self, data: Union[list, tuple]) -> None:
|
|
3338
3402
|
if data is None:
|
|
3339
3403
|
headers_to_add = 0
|
|
@@ -69,12 +69,9 @@ def _table_data(table, include_index: bool):
|
|
|
69
69
|
into the CSV field, the Markdown cell or the record. It leaves here as
|
|
70
70
|
``None``, which every writer already turns into an empty cell.
|
|
71
71
|
"""
|
|
72
|
-
missing = table.missing
|
|
73
72
|
headers = [str(header) for header in table.headers]
|
|
74
|
-
rows
|
|
75
|
-
|
|
76
|
-
for row in table.rows
|
|
77
|
-
]
|
|
73
|
+
# ``table.rows`` is already a copy with ``None`` in the gaps.
|
|
74
|
+
rows = table.rows
|
|
78
75
|
if include_index:
|
|
79
76
|
# The stored index column holds a counter object that only the
|
|
80
77
|
# renderer knows how to read, so exports wrote its ``repr`` in every
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flexablelib
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: Fast, dependency-free terminal tables for Python: 56 border styles, ANSI colors, cell merges, decimal alignment, width fitting, and CSV/Markdown/HTML/Excel/LaTeX I/O.
|
|
5
5
|
Home-page: https://github.com/Opus-Perpetuus/flexablelib
|
|
6
6
|
Author: Benjamin Ramirez
|
|
@@ -439,6 +439,15 @@ table.parse_str_numbers = True
|
|
|
439
439
|
|
|
440
440
|
Values with leading zeros are left alone, so `'007'` stays a string.
|
|
441
441
|
|
|
442
|
+
`table.rows` is a copy of the data, with `None` in empty cells (the same values
|
|
443
|
+
as `to_records()`), so editing it does not change the table. Use `add_row` and
|
|
444
|
+
`set_cell` instead:
|
|
445
|
+
|
|
446
|
+
```python
|
|
447
|
+
table.set_cell(0, 'Uptime', 98.2) # row position, column position or header
|
|
448
|
+
table.set_cell(1, 2, table.missing) # empty a cell
|
|
449
|
+
```
|
|
450
|
+
|
|
442
451
|
## Merging cells
|
|
443
452
|
|
|
444
453
|
Render a rectangular block as a single cell, across columns, down rows, or
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""2.1.0: ``Table.rows`` is a copy with ``None`` in the gaps; ``set_cell``."""
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from flexablelib import Table
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _table():
|
|
8
|
+
table = Table(rows=[['api', 99.9], ['auth']], headers=['Service', 'Uptime'])
|
|
9
|
+
table.add_row()
|
|
10
|
+
table.add_column('Region', ['us', table.missing, 'eu'])
|
|
11
|
+
return table
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_rows_is_a_new_list_each_call():
|
|
15
|
+
table = _table()
|
|
16
|
+
first, second = table.rows, table.rows
|
|
17
|
+
assert first == second
|
|
18
|
+
assert first is not second
|
|
19
|
+
assert all(a is not b for a, b in zip(first, second))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_mutating_rows_does_not_change_the_table():
|
|
23
|
+
table = Table(rows=[['a', 1], ['b', 2]], headers=['k', 'v'])
|
|
24
|
+
before = str(table)
|
|
25
|
+
rows = table.rows
|
|
26
|
+
rows[0][1] = 999
|
|
27
|
+
rows.append(['c', 3])
|
|
28
|
+
del rows[1]
|
|
29
|
+
assert table.rows == [['a', 1], ['b', 2]]
|
|
30
|
+
assert str(table) == before
|
|
31
|
+
assert table.row_count == 2
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_empty_and_missing_cells_are_none():
|
|
35
|
+
table = _table()
|
|
36
|
+
table.add_row(['x', table.missing, 'mx'])
|
|
37
|
+
rows = table.rows
|
|
38
|
+
assert rows[1] == ['auth', None, None]
|
|
39
|
+
assert rows[2][:2] == [None, None]
|
|
40
|
+
assert rows[3] == ['x', None, 'mx']
|
|
41
|
+
assert 'ValuePlacer' not in repr(rows)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_rows_match_records_and_exports():
|
|
45
|
+
table = _table()
|
|
46
|
+
records = table.to_records()
|
|
47
|
+
assert [list(r.values()) for r in records] == table.rows
|
|
48
|
+
assert [list(r.keys()) for r in records][0] == table.headers
|
|
49
|
+
csv_lines = table.to_csv().splitlines()[1:]
|
|
50
|
+
expected = [','.join('' if v is None else str(v) for v in row)
|
|
51
|
+
for row in table.rows]
|
|
52
|
+
assert csv_lines == expected
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_set_cell_updates_render_and_rows():
|
|
56
|
+
table = Table(rows=[['api', 99.9], ['auth', 98.0]],
|
|
57
|
+
headers=['Service', 'Uptime'])
|
|
58
|
+
table.set_cell(0, 'Uptime', 12.5)
|
|
59
|
+
table.set_cell(-1, 0, 'login')
|
|
60
|
+
assert table.rows == [['api', 12.5], ['login', 98.0]]
|
|
61
|
+
assert table.columns['Uptime'] == [12.5, 98.0]
|
|
62
|
+
out = str(table)
|
|
63
|
+
assert '12.5' in out and 'login' in out and 'auth' not in out
|
|
64
|
+
table.show_index = True
|
|
65
|
+
assert 'login' in str(table)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_set_cell_missing_empties_cell():
|
|
69
|
+
table = Table(rows=[[1, 2]], headers=['a', 'b'])
|
|
70
|
+
table.set_cell(0, 'b', table.missing)
|
|
71
|
+
assert table.rows == [[1, None]]
|
|
72
|
+
assert table.to_records() == [{'a': 1, 'b': None}]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_set_cell_parses_numbers_when_enabled():
|
|
76
|
+
table = Table(rows=[['x', 1]], headers=['k', 'v'])
|
|
77
|
+
table.parse_str_numbers = True
|
|
78
|
+
table.set_cell(0, 'v', '42')
|
|
79
|
+
assert table.rows == [['x', 42]]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.parametrize('row, column, error', [
|
|
83
|
+
(5, 0, IndexError),
|
|
84
|
+
(0, 9, IndexError),
|
|
85
|
+
(0, 'nope', KeyError),
|
|
86
|
+
(1.0, 0, TypeError),
|
|
87
|
+
(True, 0, TypeError),
|
|
88
|
+
(0, 1.5, TypeError),
|
|
89
|
+
])
|
|
90
|
+
def test_set_cell_rejects_bad_coordinates(row, column, error):
|
|
91
|
+
table = Table(rows=[[1, 2]], headers=['a', 'b'])
|
|
92
|
+
with pytest.raises(error):
|
|
93
|
+
table.set_cell(row, column, 0)
|
|
94
|
+
assert table.rows == [[1, 2]]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|