flexablelib 2.2.4__tar.gz → 2.3.1__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.
Files changed (74) hide show
  1. {flexablelib-2.2.4 → flexablelib-2.3.1}/CHANGELOG.md +43 -0
  2. {flexablelib-2.2.4/flexablelib.egg-info → flexablelib-2.3.1}/PKG-INFO +23 -1
  3. {flexablelib-2.2.4 → flexablelib-2.3.1}/README.md +22 -0
  4. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/columns.py +3 -0
  5. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/table.py +22 -18
  6. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/utils.py +0 -80
  7. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/writers.py +1 -1
  8. {flexablelib-2.2.4 → flexablelib-2.3.1/flexablelib.egg-info}/PKG-INFO +23 -1
  9. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib.egg-info/SOURCES.txt +4 -0
  10. {flexablelib-2.2.4 → flexablelib-2.3.1}/package.json +1 -1
  11. flexablelib-2.3.1/tests/test_align_indicators.py +77 -0
  12. flexablelib-2.3.1/tests/test_public_api_edges.py +63 -0
  13. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_stress_matrix.py +7 -0
  14. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v219_fixes.py +3 -2
  15. flexablelib-2.3.1/tests/test_v230_none.py +88 -0
  16. flexablelib-2.3.1/tests/test_v231_fixes.py +31 -0
  17. {flexablelib-2.2.4 → flexablelib-2.3.1}/tools/stress_matrix.py +57 -2
  18. {flexablelib-2.2.4 → flexablelib-2.3.1}/LICENSE +0 -0
  19. {flexablelib-2.2.4 → flexablelib-2.3.1}/MANIFEST.in +0 -0
  20. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/__init__.py +0 -0
  21. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/_speedups.c +0 -0
  22. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/_width_tables.h +0 -0
  23. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/cells.py +0 -0
  24. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/colors.py +0 -0
  25. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/fast.py +0 -0
  26. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/merges.py +0 -0
  27. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/options.py +0 -0
  28. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/py.typed +0 -0
  29. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/readers.py +0 -0
  30. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/style_compositions.py +0 -0
  31. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/table_strings.py +0 -0
  32. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib/text_width.py +0 -0
  33. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib.egg-info/dependency_links.txt +0 -0
  34. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib.egg-info/requires.txt +0 -0
  35. {flexablelib-2.2.4 → flexablelib-2.3.1}/flexablelib.egg-info/top_level.txt +0 -0
  36. {flexablelib-2.2.4 → flexablelib-2.3.1}/pytest.ini +0 -0
  37. {flexablelib-2.2.4 → flexablelib-2.3.1}/setup.cfg +0 -0
  38. {flexablelib-2.2.4 → flexablelib-2.3.1}/setup.py +0 -0
  39. {flexablelib-2.2.4 → flexablelib-2.3.1}/style_examples.md +0 -0
  40. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/conftest.py +0 -0
  41. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/helpers.py +0 -0
  42. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_cells.py +0 -0
  43. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_columns.py +0 -0
  44. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_excel.py +0 -0
  45. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_features.py +0 -0
  46. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_issues.py +0 -0
  47. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_merge_edge_matrix.py +0 -0
  48. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_merges.py +0 -0
  49. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_readme_examples.py +0 -0
  50. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_style_line_widths.py +0 -0
  51. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_styles.py +0 -0
  52. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_text_width.py +0 -0
  53. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_two_pass_measurement.py +0 -0
  54. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_upstream_issues.py +0 -0
  55. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v2021_fixes.py +0 -0
  56. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v210_rows_copy.py +0 -0
  57. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v2110_fixes.py +0 -0
  58. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v211_fixes.py +0 -0
  59. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v213_features.py +0 -0
  60. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v214_features.py +0 -0
  61. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v215_features.py +0 -0
  62. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v216_features.py +0 -0
  63. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v217_features.py +0 -0
  64. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v218_features.py +0 -0
  65. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v219_coverage.py +0 -0
  66. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v220_exports.py +0 -0
  67. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v221_fixes.py +0 -0
  68. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v222_fixes.py +0 -0
  69. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v223_fixes.py +0 -0
  70. {flexablelib-2.2.4 → flexablelib-2.3.1}/tests/test_v224_fixes.py +0 -0
  71. {flexablelib-2.2.4 → flexablelib-2.3.1}/tools/benchmark.py +0 -0
  72. {flexablelib-2.2.4 → flexablelib-2.3.1}/tools/generate_width_tables.py +0 -0
  73. {flexablelib-2.2.4 → flexablelib-2.3.1}/tools/readme_gallery.py +0 -0
  74. {flexablelib-2.2.4 → flexablelib-2.3.1}/tools/text_to_png.py +0 -0
@@ -2,6 +2,49 @@
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.3.1] - 2026-11-10
6
+
7
+ ### Fixed
8
+ - ``to_html(paginate=None)`` raised ``TypeError``; ``None`` now means no
9
+ paging, like ``0``.
10
+ - ``index_start = None`` / ``index_step = None`` raised ``TypeError``;
11
+ they now fall back to the defaults (``0`` and ``1``), as non-numeric
12
+ strings already did.
13
+
14
+ ### Internal
15
+ - Removed unused helpers from ``flexablelib.utils`` (``float_format``,
16
+ ``is_list``/``is_tuple``/``is_dict``/``is_set``/``is_str``/``is_bytes``,
17
+ ``length_of_elements``, ``flatten``, ``delete_repetitions``). None were
18
+ part of the public API or called anywhere in the package.
19
+ - Tests for alignment indicators on ``pipes`` and ``sticks``: centred and
20
+ right markers, wide characters, one-character and zero-width columns.
21
+ - Behaviour tests for public edge paths: `add_dividers` with one iterable,
22
+ `hrules=True`, invalid `hrules`/`vrules`/`border_text` arguments,
23
+ `clear_border_texts`, non-callable `row_filter`/`color_rule`, and
24
+ out-of-range `hide_columns`.
25
+
26
+ ## [2.3.0] - 2026-11-07
27
+
28
+ ### Changed (visible behaviour)
29
+ - Explicit ``None`` now displays ``missing_value`` (blank by default), just
30
+ like a padding gap or ``table.missing``. Previously it printed ``None``.
31
+ Use the string ``"None"`` to retain that literal output. Applies to every
32
+ style, printing/``compose``, pagination, streaming and transposition.
33
+ - A numeric column containing ``None`` keeps its numeric type, alignment
34
+ and decimal axis; wrapping no longer splits its numbers as text.
35
+ - Derived tables used for pagination/streaming preserve gaps as missing data
36
+ instead of converting the placeholder to text before inferring types.
37
+ ``Table(rows=t.rows)`` preserves the visible cells with matching settings.
38
+ Raw rows and export missing-value semantics are unchanged.
39
+
40
+ ### Tests and documentation
41
+ - Regressions across all 56 styles, three missing-value displays and all
42
+ render paths; raw/formatted exports, row round-trips and numeric wrapping.
43
+ - The stress matrix now compares None, padding sentinels and row round-trips
44
+ in every style/theme and mode; stream budgets include decimal-axis width
45
+ and a feasible terminal budget (narrow fits are covered outside stream).
46
+ - README and ``docs/MISSING_VALUES.md`` explain the visible change.
47
+
5
48
  ## [2.2.4] - 2026-11-07
6
49
 
7
50
  Found by a new stress matrix (``tools/stress_matrix.py``): every style and
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.2.4
3
+ Version: 2.3.1
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
@@ -347,6 +347,28 @@ print(new_table)
347
347
  ```
348
348
  The missing value aligns as if it was of the same type of the other data in the column.
349
349
 
350
+ **Changed in 2.3.0:** an explicit `None` is a missing cell, just like a
351
+ padding gap or `table.missing`. It displays `missing_value` (blank by default),
352
+ not the text `"None"`. Set `table.missing_value = '?'` to show gaps explicitly.
353
+ Use the string `"None"` if you want that literal text. This applies to printing,
354
+ `compose()`, pagination, streaming, and transposition in every style.
355
+
356
+ Missing cells do not turn numeric columns into text: numeric alignment and
357
+ the decimal axis are preserved, and `overflow='wrap'` does not split floats
358
+ because a column contains `None`. Raw `rows` and exports still represent gaps
359
+ as `None`; rendering `Table(rows=table.rows)` reproduces the same cells (copy
360
+ headers and display settings too if you changed them).
361
+
362
+ ```python
363
+ table = Table(rows=[[924.87], [None], [1.25]])
364
+ assert 'None' not in table.compose()
365
+ assert Table(rows=table.rows).compose() == table.compose()
366
+ table.missing_value = '?' # changes the display, not stored None values
367
+ ```
368
+
369
+ See [missing-cell semantics](docs/MISSING_VALUES.md) for migration details.
370
+
371
+
350
372
  This shows how to get the row and column count. If the index is shown, this count remains unaffected by that column, although, you can get the internal count.
351
373
 
352
374
  ### Code Example
@@ -282,6 +282,28 @@ print(new_table)
282
282
  ```
283
283
  The missing value aligns as if it was of the same type of the other data in the column.
284
284
 
285
+ **Changed in 2.3.0:** an explicit `None` is a missing cell, just like a
286
+ padding gap or `table.missing`. It displays `missing_value` (blank by default),
287
+ not the text `"None"`. Set `table.missing_value = '?'` to show gaps explicitly.
288
+ Use the string `"None"` if you want that literal text. This applies to printing,
289
+ `compose()`, pagination, streaming, and transposition in every style.
290
+
291
+ Missing cells do not turn numeric columns into text: numeric alignment and
292
+ the decimal axis are preserved, and `overflow='wrap'` does not split floats
293
+ because a column contains `None`. Raw `rows` and exports still represent gaps
294
+ as `None`; rendering `Table(rows=table.rows)` reproduces the same cells (copy
295
+ headers and display settings too if you changed them).
296
+
297
+ ```python
298
+ table = Table(rows=[[924.87], [None], [1.25]])
299
+ assert 'None' not in table.compose()
300
+ assert Table(rows=table.rows).compose() == table.compose()
301
+ table.missing_value = '?' # changes the display, not stored None values
302
+ ```
303
+
304
+ See [missing-cell semantics](docs/MISSING_VALUES.md) for migration details.
305
+
306
+
285
307
  This shows how to get the row and column count. If the index is shown, this count remains unaffected by that column, although, you can get the internal count.
286
308
 
287
309
  ### Code Example
@@ -628,6 +628,9 @@ def _typify_column(column: Union[list, tuple],
628
628
  if index_column:
629
629
  # If it is the index column, it will be took in count as int.
630
630
  identified_types.append(int.__name__)
631
+ elif row is None:
632
+ # An explicit None is the same gap as the padding sentinel.
633
+ identified_types.append(TYPE_NAMES.value_placer_)
631
634
  elif row != '':
632
635
  # Get the type as long as is not an empty string.
633
636
  identified_types.append(type(row).__name__)
@@ -1244,7 +1244,11 @@ class Table(object):
1244
1244
  @property
1245
1245
  def missing_value(self) -> Any:
1246
1246
  """
1247
- A placeholder for empty cells.
1247
+ A placeholder for missing cells, including explicit None (since 2.3).
1248
+
1249
+ None does not turn a numeric column into text. Use the string
1250
+ 'None' to display that literal word. Raw rows and exports keep
1251
+ missing cells as None, independently of this display placeholder.
1248
1252
 
1249
1253
  Default is::
1250
1254
 
@@ -2166,14 +2170,18 @@ class Table(object):
2166
2170
  def index_start(self, value: int):
2167
2171
  try:
2168
2172
  self.__i_start = int(value)
2169
- except ValueError:
2173
+ except (TypeError, ValueError):
2174
+ # None or any non-numeric value falls back to the default,
2175
+ # the same way a non-numeric string always has.
2170
2176
  self.__i_start = 0
2171
2177
 
2172
2178
  @index_step.setter
2173
2179
  def index_step(self, value: int):
2174
2180
  try:
2175
2181
  self.__i_step = int(value)
2176
- except ValueError:
2182
+ except (TypeError, ValueError):
2183
+ # None or any non-numeric value falls back to the default,
2184
+ # the same way a non-numeric string always has.
2177
2185
  self.__i_step = 1
2178
2186
 
2179
2187
  @index_title.setter
@@ -2684,8 +2692,8 @@ class Table(object):
2684
2692
 
2685
2693
  A cell holding this renders as ``missing_value`` and does not affect
2686
2694
  the column's inferred type, so a numeric column with gaps stays
2687
- numeric and stays right-aligned. Assigning None or '' instead would
2688
- make the column textual.
2695
+ numeric and stays right-aligned. None does the same; an empty string
2696
+ would make the column textual.
2689
2697
 
2690
2698
  Used by the readers to represent NaN and NULL, and available for
2691
2699
  building tables with gaps by hand::
@@ -4592,20 +4600,16 @@ class Table(object):
4592
4600
  # For adding the missing value where the ValuePlacer
4593
4601
  # is used (in the rows with index).
4594
4602
  for column_i, column in enumerate(row):
4595
- if isinstance(column, ValuePlacer):
4596
- rows_with_i[row_i][column_i] = column(
4597
- self.__missing_value
4598
- )
4603
+ if column is None or isinstance(column, ValuePlacer):
4604
+ rows_with_i[row_i][column_i] = self.__missing_value
4599
4605
 
4600
4606
  # For adding the missing value where the ValuePlacer
4601
4607
  # is used.
4602
4608
  rows = [list(row) for row in self.__rows]
4603
4609
  for row_i, row in enumerate(rows):
4604
4610
  for column_i, column in enumerate(row):
4605
- if isinstance(column, ValuePlacer):
4606
- rows[row_i][column_i] = column(
4607
- self.__missing_value
4608
- )
4611
+ if column is None or isinstance(column, ValuePlacer):
4612
+ rows[row_i][column_i] = self.__missing_value
4609
4613
 
4610
4614
  # Filter and sort the display copies together so the index column
4611
4615
  # stays aligned with its row.
@@ -6283,13 +6287,13 @@ class Table(object):
6283
6287
  out.__border_texts = [dict(entry) for entry in self.__border_texts]
6284
6288
 
6285
6289
  def __stored_row(self, row_i, headers):
6286
- """One stored row with gaps turned into the missing value."""
6290
+ """One stored row with gaps kept as None for derived-table typing."""
6287
6291
  row = []
6288
6292
  for header in headers:
6289
6293
  col = self.__columns.get(header, [])
6290
- cell = col[row_i] if row_i < len(col) else self.__missing_value
6294
+ cell = col[row_i] if row_i < len(col) else None
6291
6295
  if isinstance(cell, ValuePlacer):
6292
- cell = self.__missing_value
6296
+ cell = None
6293
6297
  row.append(cell)
6294
6298
  return row
6295
6299
 
@@ -6698,8 +6702,8 @@ class Table(object):
6698
6702
  Write a self-contained HTML page with sorting, filtering and paging.
6699
6703
 
6700
6704
  Everything is inline -- no external requests -- so the file works
6701
- offline and from a file:// URL. ``paginate`` is the page size; 0 puts
6702
- every row on one page. Returns the markup when no target is given.
6705
+ offline and from a file:// URL. ``paginate`` is the page size; 0,
6706
+ False or None put every row on one page. Returns the markup when no target is given.
6703
6707
  """
6704
6708
  from .writers import to_html
6705
6709
  return to_html(self, target, title, paginate, include_index,
@@ -1,11 +1,6 @@
1
1
  import os
2
2
  import json
3
3
  import shutil
4
- from typing import Iterable, Union
5
-
6
-
7
- def float_format(number, decimal_spaces):
8
- return ''.join(['{:.', str(decimal_spaces), 'f}']).format(number)
9
4
 
10
5
 
11
6
  def get_window_size():
@@ -32,30 +27,6 @@ def get_window_size():
32
27
  return size.columns, size.lines
33
28
 
34
29
 
35
- def is_list(piece):
36
- return isinstance(piece, list)
37
-
38
-
39
- def is_tuple(piece):
40
- return isinstance(piece, tuple)
41
-
42
-
43
- def is_dict(piece):
44
- return isinstance(piece, dict)
45
-
46
-
47
- def is_set(piece):
48
- return isinstance(piece, set)
49
-
50
-
51
- def is_str(piece):
52
- return isinstance(piece, str)
53
-
54
-
55
- def is_bytes(piece):
56
- return isinstance(piece, bytes)
57
-
58
-
59
30
  def is_some_instance(piece, *instances):
60
31
  """
61
32
  Returns True if the data piece is any instance of the requested.
@@ -104,50 +75,9 @@ def is_multi_row(row):
104
75
  return all(isinstance(cell, (list, tuple)) for cell in row)
105
76
 
106
77
 
107
- def length_of_elements(element_list, index=0, lengths=None):
108
- """
109
- Returns the length of each row (sub-array) in a single array
110
- """
111
- if lengths is None:
112
- lengths = []
113
- # Will only calculate len if index is lower than the len of the array.
114
- # If it isn't less, will return the final array of lengths.
115
- if index < len(element_list):
116
-
117
- # Appends the length of the current element using the
118
- # "index" param, which starts as 0.
119
- lengths.append(len(element_list[index]))
120
-
121
- # For each time it appends a length, calls again the function, sending
122
- # the listOfElements, the lengths array with the previous value\s and the
123
- # index plus 1, last one so looks for the next element
124
- length_of_elements(element_list, index + 1, lengths)
125
-
126
- return lengths
127
-
128
-
129
- def flatten(list_to_flatten, i=0, c=0):
130
- """
131
- Flatten a list containing lists that could also contain lists,
132
- and so on
133
- """
134
- c += 1
135
- if i < len(list_to_flatten):
136
- if is_list(list_to_flatten[i]):
137
- temp = list_to_flatten.pop(i)
138
- for x in range(len(temp)):
139
- list_to_flatten.insert(i + x, temp[x])
140
- return flatten(list_to_flatten, i, c)
141
- else:
142
- return flatten(list_to_flatten, i + 1, c)
143
- else:
144
- return list_to_flatten
145
-
146
-
147
78
  def read_json(file):
148
79
  with open(file) as json_file:
149
80
  data = json.load(json_file)
150
- json_file.close()
151
81
  return data
152
82
 
153
83
 
@@ -163,16 +93,6 @@ def read_file(filename):
163
93
  return file.read()
164
94
 
165
95
 
166
- def delete_repetitions(iterable: Iterable,
167
- ) -> Union[list, tuple]:
168
- cleansed_list = []
169
- for element in iterable:
170
- if element not in cleansed_list:
171
- cleansed_list.append(element)
172
-
173
- return cleansed_list
174
-
175
-
176
96
  class IndexColumnTitle(str):
177
97
  """
178
98
  The header of the index column.
@@ -638,7 +638,7 @@ def to_html(table, target=None, title: str = 'Table', paginate: int = 25,
638
638
  'rows': row_texts,
639
639
  'keys': keys,
640
640
  'numeric': numeric_flags,
641
- 'perPage': max(0, int(paginate)),
641
+ 'perPage': max(0, int(paginate or 0)),
642
642
  }
643
643
 
644
644
  head_cells = ''.join(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flexablelib
3
- Version: 2.2.4
3
+ Version: 2.3.1
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
@@ -347,6 +347,28 @@ print(new_table)
347
347
  ```
348
348
  The missing value aligns as if it was of the same type of the other data in the column.
349
349
 
350
+ **Changed in 2.3.0:** an explicit `None` is a missing cell, just like a
351
+ padding gap or `table.missing`. It displays `missing_value` (blank by default),
352
+ not the text `"None"`. Set `table.missing_value = '?'` to show gaps explicitly.
353
+ Use the string `"None"` if you want that literal text. This applies to printing,
354
+ `compose()`, pagination, streaming, and transposition in every style.
355
+
356
+ Missing cells do not turn numeric columns into text: numeric alignment and
357
+ the decimal axis are preserved, and `overflow='wrap'` does not split floats
358
+ because a column contains `None`. Raw `rows` and exports still represent gaps
359
+ as `None`; rendering `Table(rows=table.rows)` reproduces the same cells (copy
360
+ headers and display settings too if you changed them).
361
+
362
+ ```python
363
+ table = Table(rows=[[924.87], [None], [1.25]])
364
+ assert 'None' not in table.compose()
365
+ assert Table(rows=table.rows).compose() == table.compose()
366
+ table.missing_value = '?' # changes the display, not stored None values
367
+ ```
368
+
369
+ See [missing-cell semantics](docs/MISSING_VALUES.md) for migration details.
370
+
371
+
350
372
  This shows how to get the row and column count. If the index is shown, this count remains unaffected by that column, although, you can get the internal count.
351
373
 
352
374
  ### Code Example
@@ -31,6 +31,7 @@ flexablelib.egg-info/requires.txt
31
31
  flexablelib.egg-info/top_level.txt
32
32
  tests/conftest.py
33
33
  tests/helpers.py
34
+ tests/test_align_indicators.py
34
35
  tests/test_cells.py
35
36
  tests/test_columns.py
36
37
  tests/test_excel.py
@@ -38,6 +39,7 @@ tests/test_features.py
38
39
  tests/test_issues.py
39
40
  tests/test_merge_edge_matrix.py
40
41
  tests/test_merges.py
42
+ tests/test_public_api_edges.py
41
43
  tests/test_readme_examples.py
42
44
  tests/test_stress_matrix.py
43
45
  tests/test_style_line_widths.py
@@ -62,6 +64,8 @@ tests/test_v221_fixes.py
62
64
  tests/test_v222_fixes.py
63
65
  tests/test_v223_fixes.py
64
66
  tests/test_v224_fixes.py
67
+ tests/test_v230_none.py
68
+ tests/test_v231_fixes.py
65
69
  tools/benchmark.py
66
70
  tools/generate_width_tables.py
67
71
  tools/readme_gallery.py
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flexablelib",
3
- "version": "2.2.4",
3
+ "version": "2.3.1",
4
4
  "private": true,
5
5
  "description": "Flexible console and HTML tables for Python: styles, merges, colors, widths, decimal alignment.",
6
6
  "repository": {
@@ -0,0 +1,77 @@
1
+ """Alignment indicators on the align-sensitive styles (pipes, sticks).
2
+
3
+ Every column's separator segment must name that column's alignment and be
4
+ exactly as wide as the cells under it, whatever the alignment, the width or
5
+ the characters in the cells.
6
+ """
7
+ import re
8
+
9
+ import pytest
10
+
11
+ from flexablelib import Table
12
+ from flexablelib.text_width import visible_width
13
+
14
+
15
+ def _render(rows, headers, style, align):
16
+ table = Table(rows=rows, headers=headers, style_name=style)
17
+ table.col_alignment = align
18
+ return str(table).splitlines()
19
+
20
+
21
+ def _segments(line, sep):
22
+ return line.strip(sep).split(sep)
23
+
24
+
25
+ def _assert_rules_match_cells(lines, rule_sep, cell_sep='|'):
26
+ cell_widths = [visible_width(s) for s in _segments(lines[1], cell_sep)]
27
+ for line in lines:
28
+ if line.startswith(rule_sep):
29
+ rule = [visible_width(s) for s in _segments(line, rule_sep)]
30
+ assert rule == cell_widths, line
31
+
32
+
33
+ ROWS = [['a', 1, 'x'], ['bbb', 22, 'yyyyyy']]
34
+ HEADERS = ['L', 'R', 'Center']
35
+
36
+
37
+ def test_pipes_marks_left_right_and_center():
38
+ lines = _render(ROWS, HEADERS, 'pipes', ['l', 'r', 'c'])
39
+ left, right, center = _segments(lines[1], '|')
40
+ assert re.fullmatch(r' :-+ ', left)
41
+ assert re.fullmatch(r' -+: ', right)
42
+ assert re.fullmatch(r' :-+: ', center)
43
+ _assert_rules_match_cells(lines, '|')
44
+
45
+
46
+ def test_sticks_marks_each_alignment():
47
+ lines = _render(ROWS, HEADERS, 'sticks', ['l', 'r', 'c'])
48
+ left, right, center = _segments(lines[0], '+')
49
+ assert '~<~' in left
50
+ assert '~>~' in right
51
+ assert '~^~' in center
52
+ _assert_rules_match_cells(lines, '+')
53
+
54
+
55
+ @pytest.mark.parametrize('style, rule_sep', [('pipes', '|'), ('sticks', '+')])
56
+ def test_centered_wide_characters_keep_rules_aligned(style, rule_sep):
57
+ lines = _render(
58
+ [['漢字', 1.5], ['😀', 22.25]], ['名前', '数'], style, 'c'
59
+ )
60
+ _assert_rules_match_cells(lines, rule_sep)
61
+
62
+
63
+ @pytest.mark.parametrize('style, rule_sep', [('pipes', '|'), ('sticks', '+')])
64
+ def test_centered_one_char_columns_drop_margins_not_width(style, rule_sep):
65
+ lines = _render([['a', 'b'], ['c', 'd']], ['x', 'y'], style, 'c')
66
+ _assert_rules_match_cells(lines, rule_sep)
67
+ marker = ':-:' if style == 'pipes' else '~^~'
68
+ assert _segments(lines[1 if style == 'pipes' else 0], rule_sep) == [
69
+ marker, marker
70
+ ]
71
+
72
+
73
+ def test_column_too_narrow_for_indicator_gets_plain_rule():
74
+ lines = _render([['', 1], ['', 2]], ['', 'n'], 'sticks', ['l', 'r'])
75
+ _assert_rules_match_cells(lines, '+')
76
+ empty_segment = _segments(lines[0], '+')[0]
77
+ assert '~' not in empty_segment
@@ -0,0 +1,63 @@
1
+ import pytest
2
+
3
+ from flexablelib import Table
4
+
5
+
6
+ def _table():
7
+ return Table(rows=[[1, 'a'], [2, 'b'], [3, 'c']], headers=['n', 's'])
8
+
9
+
10
+ def test_add_dividers_accepts_one_iterable():
11
+ by_iterable = _table()
12
+ by_iterable.add_dividers([0, 1])
13
+ by_args = _table()
14
+ by_args.add_dividers(0, 1)
15
+ assert by_iterable.compose() == by_args.compose()
16
+ assert by_iterable.compose() != _table().compose()
17
+
18
+
19
+ def test_hrules_true_means_all():
20
+ table = _table()
21
+ table.hrules = True
22
+ assert table.hrules == 'all'
23
+
24
+
25
+ def test_invalid_hrules_and_vrules_raise():
26
+ table = _table()
27
+ with pytest.raises(ValueError):
28
+ table.hrules = 'sometimes'
29
+ with pytest.raises(ValueError):
30
+ table.vrules = 'sometimes'
31
+
32
+
33
+ def test_border_text_rejects_unknown_where_and_align():
34
+ table = _table()
35
+ with pytest.raises(ValueError, match='where'):
36
+ table.border_text('x', where='middle')
37
+ with pytest.raises(ValueError, match='align'):
38
+ table.border_text('x', align='justify')
39
+
40
+
41
+ def test_clear_border_texts_restores_plain_render():
42
+ table = _table()
43
+ plain = table.compose()
44
+ table.border_text('hi', where='bottom')
45
+ assert table.compose() != plain
46
+ assert table.clear_border_texts() is table
47
+ assert table.compose() == plain
48
+
49
+
50
+ @pytest.mark.parametrize('name', ['row_filter', 'color_rule'])
51
+ def test_callable_options_reject_non_callables(name):
52
+ table = _table()
53
+ with pytest.raises(TypeError):
54
+ setattr(table, name, 'not callable')
55
+ setattr(table, name, None)
56
+ assert getattr(table, name) is None
57
+
58
+
59
+ def test_hide_columns_out_of_range_index_raises():
60
+ table = _table()
61
+ table.hide_columns = [5]
62
+ with pytest.raises(ValueError, match='out of range'):
63
+ table.compose()
@@ -45,3 +45,10 @@ def test_render_invariants(case):
45
45
  @pytest.mark.parametrize('combo', range(len(matrix.EVERYTHING)))
46
46
  def test_exports_round_trip(style, combo):
47
47
  assert matrix.check_exports(style, matrix.EVERYTHING[combo]) == []
48
+
49
+
50
+ def test_none_padding_and_raw_rows_roundtrip_matrix():
51
+ count, failures = matrix.none_vs_missing(['rounded', 'grid', 'plain',
52
+ 'theme:mono', 'theme:report'])
53
+ assert count == 75
54
+ assert failures == []
@@ -41,11 +41,12 @@ def test_max_width_trims_each_line_of_a_multiline_cell():
41
41
  assert len(_widths(table)) == 1
42
42
 
43
43
 
44
- def test_max_width_trims_none_cells_like_before():
44
+ def test_max_width_renders_none_as_blank_since_v230():
45
45
  table = Table(rows=[[None], ['x']], headers=['c'])
46
46
  table.style_name = 'ascii'
47
47
  table.column_max_width = 3
48
- assert '| ... |' in strip_ansi(table.compose()).splitlines()
48
+ assert '| |' in strip_ansi(table.compose()).splitlines()
49
+ assert 'None' not in table.compose()
49
50
 
50
51
 
51
52
  @pytest.mark.parametrize('style', Table().possible_styles)
@@ -0,0 +1,88 @@
1
+ """None is a missing cell, not the string 'None' (visible change in 2.3)."""
2
+ import pytest
3
+
4
+ from flexablelib import Table
5
+ from flexablelib.style_compositions import __style_compositions as catalogue
6
+ from flexablelib.text_width import visible_width
7
+
8
+
9
+ def make(style, missing, sentinel=False):
10
+ t = Table(headers=['id', 'float', 'int', 'text'], style_name=style,
11
+ missing_val=missing)
12
+ gap = t.missing if sentinel else None
13
+ for row in [['r0', 924.87, 31, '東京 😀'], ['r1', gap, gap, gap],
14
+ ['r2', -1.25, 2, 'épsilon'], ['r3', gap, 107, 'tail']]:
15
+ t.add_row(row)
16
+ t.max_width = 1000
17
+ return t
18
+
19
+
20
+ @pytest.mark.parametrize('style', catalogue._fields)
21
+ @pytest.mark.parametrize('missing', ['', '?', '欠測 😀'])
22
+ def test_none_matches_padding_sentinel_in_every_render_path(style, missing):
23
+ a, b = make(style, missing), make(style, missing, sentinel=True)
24
+ assert a.compose() == b.compose()
25
+ assert str(a) == str(b)
26
+ assert a.paginate(2) == b.paginate(2)
27
+ assert a.paginate(2, freeze_header=False) == b.paginate(2, freeze_header=False)
28
+ assert list(a.stream([])) == list(b.stream([]))
29
+ assert a.transpose().compose() == b.transpose().compose()
30
+ assert a.rows == b.rows
31
+ assert a.to_records() == b.to_records()
32
+ assert a.to_records(formatted=True) == b.to_records(formatted=True)
33
+ assert a.to_csv() == b.to_csv()
34
+ assert a.to_html() == b.to_html()
35
+ assert a.to_markdown() == b.to_markdown()
36
+ assert 'None' not in a.compose()
37
+
38
+
39
+ @pytest.mark.parametrize('missing', ['', '?', 'missing'])
40
+ @pytest.mark.parametrize('index', [False, True])
41
+ def test_none_preserves_numeric_alignment_and_decimal_axis_with_wrap(missing, index):
42
+ t = make('ascii', missing)
43
+ t.show_index = index
44
+ t.overflow = 'wrap'
45
+ t.column_max_width = 7
46
+ out = t.compose()
47
+ lines = out.splitlines()
48
+ assert len({visible_width(line) for line in lines}) == 1
49
+ # A missing cell must not turn numbers into text that wraps over lines.
50
+ assert '924.87' in out
51
+ assert '-1.25' in out
52
+ assert '31 |' in out
53
+ numeric = [line for line in lines if '924.87' in line or '-1.25' in line]
54
+ assert numeric[0].index('.') == numeric[1].index('.')
55
+
56
+
57
+ @pytest.mark.parametrize('style', catalogue._fields)
58
+ def test_rows_roundtrip_keeps_blanks_and_column_types(style):
59
+ t = Table(rows=[[2.75, 3], [None], [24.5, None]], style_name=style)
60
+ assert Table(rows=t.rows, style_name=style).compose() == t.compose()
61
+ t.missing_value = '?'
62
+ copy = Table(rows=t.rows, headers=t.headers, style_name=style, missing_val='?')
63
+ assert copy.compose() == t.compose()
64
+ assert copy.rows == t.rows
65
+
66
+
67
+ def test_stream_incoming_none_matches_an_incoming_padding_sentinel():
68
+ a = Table(headers=['n', 'i'], missing_val='?')
69
+ b = Table(headers=['n', 'i'], missing_val='?')
70
+ for t in (a, b):
71
+ t.column_min_width = 12
72
+ t.max_width = 100
73
+ rows = [[2.75, 3], [None, None], [24.5, 22]]
74
+ sentinel_rows = [[2.75, 3], [b.missing, b.missing], [24.5, 22]]
75
+ assert list(a.stream(rows, append=True)) == list(b.stream(sentinel_rows, append=True))
76
+ assert a.rows == rows
77
+ assert a.compose() == b.compose()
78
+
79
+
80
+ def test_missing_value_is_dynamic_and_storage_stays_raw():
81
+ t = Table(rows=[[None], [2.75]], headers=['n'])
82
+ assert t.rows == [[None], [2.75]]
83
+ assert 'None' not in t.compose()
84
+ t.missing_value = '?'
85
+ assert '?' in t.compose()
86
+ assert t.rows == [[None], [2.75]]
87
+ assert t.to_records() == [{'n': None}, {'n': 2.75}]
88
+ assert t.to_records(formatted=True)[0] == {'n': None}
@@ -0,0 +1,31 @@
1
+ from flexablelib import Table
2
+
3
+
4
+ def _table():
5
+ return Table(rows=[[10, 'a'], [20, 'b']], headers=['n', 's'])
6
+
7
+
8
+ def test_to_html_paginate_none_shows_all_rows():
9
+ html = _table().to_html(paginate=None)
10
+ assert '"perPage": 0' in html
11
+ assert html == _table().to_html(paginate=0)
12
+
13
+
14
+ def test_index_start_none_falls_back_to_zero():
15
+ table = _table()
16
+ table.index_start = 5
17
+ table.index_start = None
18
+ assert table.index_start == 0
19
+ table.show_index = True
20
+ lines = table.compose().splitlines()
21
+ assert any('| 0 |' in line for line in lines)
22
+
23
+
24
+ def test_index_step_none_falls_back_to_one():
25
+ table = _table()
26
+ table.index_step = 3
27
+ table.index_step = None
28
+ assert table.index_step == 1
29
+ table.show_index = True
30
+ out = table.compose()
31
+ assert '| 0 |' in out and '| 1 |' in out
@@ -364,8 +364,15 @@ def run_case(style, config, header_style=None):
364
364
  continue
365
365
  dict(FACTORS[name])[label](t2)
366
366
  # stream freezes widths before rows arrive; numbers are never
367
- # cut (by design), so give every column room for the widest one.
368
- t2.column_min_width = 14
367
+ # cut (by design), so give every column room for its decimal axis too (including
368
+ # a long integer alongside scientific notation).
369
+ # Numeric columns containing None now remain numeric. A caller's
370
+ # tiny cap/terminal budget cannot be kept as well as an uncut
371
+ # number: stream documents that frozen-width precondition. Test
372
+ # narrow fits in compose/paginate; use a feasible budget here.
373
+ t2.column_min_width = 20
374
+ t2.column_max_width = 20
375
+ t2.max_width = BIG
369
376
  outs = ['\n'.join(t2.stream(make_rows()))]
370
377
  elif mode == 'transpose':
371
378
  outs = [t.transpose().compose()]
@@ -565,6 +572,50 @@ def stream_vs_compose():
565
572
  return n, bad
566
573
 
567
574
 
575
+ def none_vs_missing(styles):
576
+ """None, an internal padding gap, and rows round-trip draw identically."""
577
+ bad, n = [], 0
578
+ for style in styles:
579
+ for missing in ('', '?', '欠測 😀'):
580
+ tables = []
581
+ for sentinel in (False, True):
582
+ t = Table(headers=['id', 'number', 'int'], missing_val=missing)
583
+ if style.startswith('theme:'):
584
+ t.apply_theme(style[6:])
585
+ else:
586
+ t.style_name = style
587
+ gap = t.missing if sentinel else None
588
+ for row in [['r0', 924.87, 31], ['r1', gap, gap],
589
+ ['r2', -1.25, 2]]:
590
+ t.add_row(row)
591
+ t.max_width = BIG
592
+ t.overflow = 'wrap'
593
+ t.column_max_width = 8
594
+ tables.append(t)
595
+ a, b = tables
596
+ clone = Table(rows=a.rows, headers=a.headers, missing_val=missing,
597
+ style_name=a.style_name)
598
+ a._Table__copy_display_settings(clone)
599
+ clone.zebra = a.zebra
600
+ for label, render in (
601
+ ('compose', lambda t: t.compose()),
602
+ ('paginate', lambda t: t.paginate(2)),
603
+ ('paginate_nofreeze', lambda t: t.paginate(2, freeze_header=False)),
604
+ ('stream', lambda t: list(t.stream([]))),
605
+ ('transpose', lambda t: t.transpose().compose()),
606
+ ):
607
+ n += 1
608
+ try:
609
+ expected = render(b)
610
+ if render(a) != expected or render(clone) != expected:
611
+ bad.append({'style': style, 'config': {'mode': label},
612
+ 'problems': [('none-roundtrip', repr(missing))]})
613
+ except Exception as e:
614
+ bad.append({'style': style, 'config': {'mode': label},
615
+ 'problems': [('exception', str(e))]})
616
+ return n, bad
617
+
618
+
568
619
  def main(argv=None):
569
620
  import argparse
570
621
  ap = argparse.ArgumentParser()
@@ -580,6 +631,10 @@ def main(argv=None):
580
631
  results, n = [], 0
581
632
  if a.mode in ('streamcmp', 'all'):
582
633
  n, results = stream_vs_compose()
634
+ if a.mode in ('nonecmp', 'all'):
635
+ count, failures = none_vs_missing(styles)
636
+ n += count
637
+ results.extend(failures)
583
638
  for style, config in iter_cases(a.mode, styles):
584
639
  n += 1
585
640
  probs = run_case(style, config)
File without changes
File without changes
File without changes
File without changes
File without changes