jsonjsdb 0.8.2__tar.gz → 0.8.4__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.
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/PKG-INFO +1 -1
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/pyproject.toml +13 -4
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/evolution.py +7 -5
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/loader.py +2 -3
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/writer.py +10 -5
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/.gitignore +0 -0
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/LICENSE +0 -0
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/README.md +0 -0
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/__init__.py +0 -0
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/database.py +0 -0
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/py.typed +0 -0
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/table.py +0 -0
- {jsonjsdb-0.8.2 → jsonjsdb-0.8.4}/src/jsonjsdb/types.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "jsonjsdb"
|
|
7
|
-
version = "0.8.
|
|
7
|
+
version = "0.8.4"
|
|
8
8
|
description = "Python library for JSONJS database loading"
|
|
9
9
|
authors = [{ name = "datannur" }]
|
|
10
10
|
readme = "README.md"
|
|
@@ -31,9 +31,9 @@ Issues = "https://github.com/datannur/jsonjsdb/issues"
|
|
|
31
31
|
|
|
32
32
|
[dependency-groups]
|
|
33
33
|
dev = [
|
|
34
|
-
"pytest",
|
|
35
|
-
"pytest-cov",
|
|
36
|
-
"ruff",
|
|
34
|
+
"pytest>=7.0",
|
|
35
|
+
"pytest-cov>=4.0",
|
|
36
|
+
"ruff>=0.4.0",
|
|
37
37
|
"pyright>=1.1.400",
|
|
38
38
|
]
|
|
39
39
|
|
|
@@ -53,6 +53,15 @@ include = ["src/jsonjsdb"]
|
|
|
53
53
|
pythonVersion = "3.9"
|
|
54
54
|
typeCheckingMode = "standard"
|
|
55
55
|
|
|
56
|
+
[tool.uv]
|
|
57
|
+
constraint-dependencies = [
|
|
58
|
+
"colorama>=0.4",
|
|
59
|
+
"et-xmlfile>=2.0",
|
|
60
|
+
"iniconfig>=2.0",
|
|
61
|
+
"packaging>=21.0",
|
|
62
|
+
"toml>=0.10",
|
|
63
|
+
]
|
|
64
|
+
|
|
56
65
|
[tool.coverage.run]
|
|
57
66
|
source = ["src/jsonjsdb"]
|
|
58
67
|
branch = true
|
|
@@ -331,7 +331,7 @@ def load_evolution(path: Path, xlsx_path: Path | None = None) -> list[EvolutionE
|
|
|
331
331
|
if not evolution_path.exists():
|
|
332
332
|
return []
|
|
333
333
|
|
|
334
|
-
with open(evolution_path) as f:
|
|
334
|
+
with open(evolution_path, encoding="utf-8") as f:
|
|
335
335
|
data = json.load(f)
|
|
336
336
|
|
|
337
337
|
return [
|
|
@@ -410,8 +410,8 @@ def save_evolution(
|
|
|
410
410
|
evolution_json_path = path / "evolution.json"
|
|
411
411
|
data = [entry.to_dict() for entry in entries]
|
|
412
412
|
|
|
413
|
-
with open(evolution_json_path, "w") as f:
|
|
414
|
-
json.dump(data, f, indent=2, ensure_ascii=False)
|
|
413
|
+
with open(evolution_json_path, "w", encoding="utf-8") as f:
|
|
414
|
+
json.dump(data, f, indent=2, ensure_ascii=False, allow_nan=False)
|
|
415
415
|
f.write("\n")
|
|
416
416
|
|
|
417
417
|
# Write evolution.json.js
|
|
@@ -444,10 +444,12 @@ def save_evolution(
|
|
|
444
444
|
]
|
|
445
445
|
rows.append(row)
|
|
446
446
|
|
|
447
|
-
json_array = json.dumps(
|
|
447
|
+
json_array = json.dumps(
|
|
448
|
+
rows, ensure_ascii=False, separators=(",", ":"), allow_nan=False
|
|
449
|
+
)
|
|
448
450
|
content = f"jsonjs.data['evolution'] = {json_array}\n"
|
|
449
451
|
|
|
450
|
-
with open(evolution_jsonjs_path, "w") as f:
|
|
452
|
+
with open(evolution_jsonjs_path, "w", encoding="utf-8") as f:
|
|
451
453
|
f.write(content)
|
|
452
454
|
|
|
453
455
|
# Write evolution.xlsx if path provided
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Load JSON files into Polars DataFrames."""
|
|
2
2
|
|
|
3
|
+
import json
|
|
3
4
|
from pathlib import Path
|
|
4
5
|
from typing import Any
|
|
5
6
|
|
|
@@ -49,7 +50,5 @@ def _convert_ids_column(col_name: str, col_type: pl.DataType) -> pl.Expr:
|
|
|
49
50
|
|
|
50
51
|
def load_table_index(path: Path) -> list[dict[str, Any]]:
|
|
51
52
|
"""Load __table__.json which contains table metadata."""
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
with open(path) as f:
|
|
53
|
+
with open(path, encoding="utf-8") as f:
|
|
55
54
|
return json.load(f)
|
|
@@ -12,8 +12,8 @@ def write_table_json(df: pl.DataFrame, path: Path) -> None:
|
|
|
12
12
|
"""Write a DataFrame to a JSON file (array of objects)."""
|
|
13
13
|
prepared_df = _prepare_df_for_write(df)
|
|
14
14
|
rows = _df_to_json_rows(prepared_df)
|
|
15
|
-
with open(path, "w") as f:
|
|
16
|
-
json.dump(rows, f, indent=2, ensure_ascii=False)
|
|
15
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
16
|
+
json.dump(rows, f, indent=2, ensure_ascii=False, allow_nan=False)
|
|
17
17
|
f.write("\n")
|
|
18
18
|
|
|
19
19
|
|
|
@@ -26,10 +26,12 @@ def write_table_jsonjs(df: pl.DataFrame, table_name: str, path: Path) -> None:
|
|
|
26
26
|
for row in prepared_df.iter_rows():
|
|
27
27
|
rows.append(list(row))
|
|
28
28
|
|
|
29
|
-
json_array = json.dumps(
|
|
29
|
+
json_array = json.dumps(
|
|
30
|
+
rows, ensure_ascii=False, separators=(",", ":"), allow_nan=False
|
|
31
|
+
)
|
|
30
32
|
content = f"jsonjs.data['{table_name}'] = {json_array}\n"
|
|
31
33
|
|
|
32
|
-
with open(path, "w") as f:
|
|
34
|
+
with open(path, "w", encoding="utf-8") as f:
|
|
33
35
|
f.write(content)
|
|
34
36
|
|
|
35
37
|
|
|
@@ -58,7 +60,8 @@ def write_table_index(
|
|
|
58
60
|
|
|
59
61
|
|
|
60
62
|
def _prepare_df_for_write(df: pl.DataFrame) -> pl.DataFrame:
|
|
61
|
-
"""Prepare DataFrame for writing: convert List columns to comma-separated strings
|
|
63
|
+
"""Prepare DataFrame for writing: convert List columns to comma-separated strings
|
|
64
|
+
and NaN to null for valid JSON output."""
|
|
62
65
|
transforms: list[pl.Expr] = []
|
|
63
66
|
|
|
64
67
|
for col_name in df.columns:
|
|
@@ -71,6 +74,8 @@ def _prepare_df_for_write(df: pl.DataFrame) -> pl.DataFrame:
|
|
|
71
74
|
.fill_null("")
|
|
72
75
|
.alias(col_name)
|
|
73
76
|
)
|
|
77
|
+
elif col_type.is_float():
|
|
78
|
+
transforms.append(pl.col(col_name).fill_nan(None))
|
|
74
79
|
else:
|
|
75
80
|
transforms.append(pl.col(col_name))
|
|
76
81
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|