rn-forge-data 0.1.3__tar.gz → 0.1.5__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.
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/PKG-INFO +27 -2
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/README.md +25 -0
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/pyproject.toml +2 -2
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/pyproject.toml.orig +2 -2
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/src/rn_forge/data/excel.py +18 -11
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/src/rn_forge/data/pandas.py +11 -4
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/LICENSE +0 -0
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/src/rn_forge/data/__init__.py +0 -0
- {rn_forge_data-0.1.3 → rn_forge_data-0.1.5}/src/rn_forge/data/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rn-forge-data
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Excel and tabular data helpers for Python programming
|
|
5
5
|
Author: Rohit Narayanan
|
|
6
6
|
Author-email: Rohit Narayanan <rohit.nn@gmail.com>
|
|
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3
|
|
|
13
13
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.14
|
|
15
15
|
Classifier: Typing :: Typed
|
|
16
|
-
Requires-Dist: rn-forge-commons>=0.8.0,<0.
|
|
16
|
+
Requires-Dist: rn-forge-commons>=0.8.0,<0.11
|
|
17
17
|
Requires-Dist: openpyxl>=3.1.5
|
|
18
18
|
Requires-Dist: tablib[xlsx]>=3.8
|
|
19
19
|
Requires-Dist: pandas>=3.0.3 ; extra == 'pandas'
|
|
@@ -37,6 +37,31 @@ Excel and tabular data helpers for Python programming, built on
|
|
|
37
37
|
`rn-forge-commons`. The base install carries `openpyxl` and `tablib[xlsx]`; the
|
|
38
38
|
`pandas` extra adds the pandas adapter.
|
|
39
39
|
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```toml
|
|
43
|
+
dependencies = ["rn-forge-data>=0.1,<0.2"]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The `pandas` extra adds `pandas` for `rn_forge.data.pandas`.
|
|
47
|
+
|
|
48
|
+
## Minimum example
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from rn_forge.data import ExcelUtils
|
|
52
|
+
|
|
53
|
+
workbook = ExcelUtils.new_workbook()
|
|
54
|
+
sheet = workbook.active
|
|
55
|
+
sheet.append(["id", "total"])
|
|
56
|
+
sheet.append([1001, 42.5])
|
|
57
|
+
ExcelUtils.write_workbook(workbook, "build/orders.xlsx")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Errors
|
|
61
|
+
|
|
62
|
+
`write_xlsx` raises `KeyError` when `column_formats` names a column the dataset
|
|
63
|
+
lacks. The pandas helpers raise `AppException` for a missing required field.
|
|
64
|
+
|
|
40
65
|
- `rn_forge.data` — the core: `ExcelUtils`, `CellFormat`, `WorkbookTemplate` and
|
|
41
66
|
`write_xlsx`. The facade re-exports the core only.
|
|
42
67
|
- `rn_forge.data.pandas` — the pandas adapter, behind the `pandas` extra:
|
|
@@ -10,6 +10,31 @@ Excel and tabular data helpers for Python programming, built on
|
|
|
10
10
|
`rn-forge-commons`. The base install carries `openpyxl` and `tablib[xlsx]`; the
|
|
11
11
|
`pandas` extra adds the pandas adapter.
|
|
12
12
|
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```toml
|
|
16
|
+
dependencies = ["rn-forge-data>=0.1,<0.2"]
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The `pandas` extra adds `pandas` for `rn_forge.data.pandas`.
|
|
20
|
+
|
|
21
|
+
## Minimum example
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from rn_forge.data import ExcelUtils
|
|
25
|
+
|
|
26
|
+
workbook = ExcelUtils.new_workbook()
|
|
27
|
+
sheet = workbook.active
|
|
28
|
+
sheet.append(["id", "total"])
|
|
29
|
+
sheet.append([1001, 42.5])
|
|
30
|
+
ExcelUtils.write_workbook(workbook, "build/orders.xlsx")
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Errors
|
|
34
|
+
|
|
35
|
+
`write_xlsx` raises `KeyError` when `column_formats` names a column the dataset
|
|
36
|
+
lacks. The pandas helpers raise `AppException` for a missing required field.
|
|
37
|
+
|
|
13
38
|
- `rn_forge.data` — the core: `ExcelUtils`, `CellFormat`, `WorkbookTemplate` and
|
|
14
39
|
`write_xlsx`. The facade re-exports the core only.
|
|
15
40
|
- `rn_forge.data.pandas` — the pandas adapter, behind the `pandas` extra:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rn-forge-data"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.5"
|
|
4
4
|
description = "Excel and tabular data helpers for Python programming"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -16,7 +16,7 @@ classifiers = [
|
|
|
16
16
|
]
|
|
17
17
|
requires-python = ">=3.14"
|
|
18
18
|
dependencies = [
|
|
19
|
-
"rn-forge-commons>=0.8.0,<0.
|
|
19
|
+
"rn-forge-commons>=0.8.0,<0.11",
|
|
20
20
|
"openpyxl>=3.1.5",
|
|
21
21
|
"tablib[xlsx]>=3.8",
|
|
22
22
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "rn-forge-data"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.5"
|
|
4
4
|
description = "Excel and tabular data helpers for Python programming"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "Rohit Narayanan", email = "rohit.nn@gmail.com" }]
|
|
@@ -18,7 +18,7 @@ classifiers = [
|
|
|
18
18
|
requires-python = ">=3.14"
|
|
19
19
|
# Internal requirements are version ranges (ADR-0004).
|
|
20
20
|
dependencies = [
|
|
21
|
-
"rn-forge-commons>=0.8.0,<0.
|
|
21
|
+
"rn-forge-commons>=0.8.0,<0.11",
|
|
22
22
|
"openpyxl>=3.1.5",
|
|
23
23
|
"tablib[xlsx]>=3.8",
|
|
24
24
|
]
|
|
@@ -11,6 +11,7 @@ from typing import TYPE_CHECKING, Any, cast
|
|
|
11
11
|
import openpyxl
|
|
12
12
|
from openpyxl.cell import WriteOnlyCell
|
|
13
13
|
from openpyxl.styles import Alignment, Border, Font, PatternFill, Protection
|
|
14
|
+
from openpyxl.utils import get_column_letter
|
|
14
15
|
from openpyxl.workbook.workbook import Workbook
|
|
15
16
|
from openpyxl.worksheet.worksheet import Worksheet
|
|
16
17
|
from rn_forge.commons.lang.dataclasses import DataclassMixin
|
|
@@ -388,19 +389,25 @@ def write_xlsx(
|
|
|
388
389
|
|
|
389
390
|
workbook = openpyxl.Workbook(write_only=True)
|
|
390
391
|
sheet = workbook.create_sheet(sheet_title)
|
|
392
|
+
width = len(headers) or dataset.width
|
|
393
|
+
dimension = (
|
|
394
|
+
f"A1:{get_column_letter(max(width, 1))}{max(len(dataset) + bool(headers), 1)}"
|
|
395
|
+
)
|
|
396
|
+
# A write-only sheet has no dimension, so a read-only loader scans the sheet
|
|
397
|
+
# twice to find one; declaring it up front avoids the second scan.
|
|
398
|
+
sheet.calculate_dimension = lambda: dimension # openpyxl reads this hook by name
|
|
391
399
|
if headers:
|
|
392
400
|
sheet.append(headers)
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
sheet.append(cells)
|
|
401
|
+
for row in cast("Any", dataset): # tablib is untyped
|
|
402
|
+
if by_index:
|
|
403
|
+
cells: list[Any] = list(row)
|
|
404
|
+
for index, fmt in by_index.items():
|
|
405
|
+
cell = WriteOnlyCell(sheet, value=cells[index])
|
|
406
|
+
cell.number_format = fmt
|
|
407
|
+
cells[index] = cell
|
|
408
|
+
sheet.append(cells)
|
|
409
|
+
else:
|
|
410
|
+
sheet.append(row)
|
|
404
411
|
return ExcelUtils.write_workbook_bytes(workbook).getvalue()
|
|
405
412
|
|
|
406
413
|
|
|
@@ -112,12 +112,19 @@ class PandasUtils:
|
|
|
112
112
|
field_name: str,
|
|
113
113
|
required: bool = True,
|
|
114
114
|
) -> str:
|
|
115
|
-
"""Return *field_name* from *row* as a string.
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
"""Return *field_name* from *row* as a stripped string.
|
|
116
|
+
|
|
117
|
+
| Value | ``required=False`` | ``required=True`` |
|
|
118
|
+
| -- | -- | -- |
|
|
119
|
+
| ``None``, ``float("nan")``, ``pandas.NA``, ``pandas.NaT`` | ``""`` | Raises ``AppException("Field is required: <name>")`` |
|
|
120
|
+
| ``0`` | ``"0"`` | ``"0"`` |
|
|
121
|
+
| ``0.0`` | ``"0.0"`` | ``"0.0"`` |
|
|
122
|
+
| ``False`` | ``"False"`` | ``"False"`` |
|
|
123
|
+
| ``""`` or whitespace-only string | ``""`` | ``""`` |
|
|
124
|
+
| Other non-missing value | ``str(value).strip()`` | ``str(value).strip()`` |
|
|
118
125
|
"""
|
|
119
126
|
field_value = PandasUtils.get_field(row, field_name, required)
|
|
120
|
-
result = str(field_value
|
|
127
|
+
result = "" if field_value is None else str(field_value).strip()
|
|
121
128
|
_LOGGER.trace(
|
|
122
129
|
"PandasUtils.get_string_field | field={} | required={} | result={}",
|
|
123
130
|
field_name,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|