Skip to content

Commit 4423ac1

Browse files
committed
0.3.4 - fix get_data_by_route
Fix: Add extra rules to `DashJsonGrid.get_data_by_route(...)` to raise an `KeyError` if a column cannot export any value.
1 parent d5e35e4 commit 4423ac1

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
1. Fix: The modification in `0.3.3` incorrectly allows `DashJsonGrid.pop_item_of_object(...)` to export a table row/cell even if the data fails to be routed. Now this situation is disallowed.
1212
2. Fix: A bug of `react-json-grid<=0.9.0` causes the selection may return an incorrect route containing `null`. Now the codes will handle this case. When routing the data, the routing will stop by the parent of the place where the `null` index is applied to. When modifying the data, using a route containing `null` will do nothing.
13-
3. Fix: Correct typos in the docstrings of `mixins`.
13+
3. Fix: Correct typos in the docstrings of `mixins` and `pytest`.
14+
4. Fix: Add extra rules to `DashJsonGrid.get_data_by_route(...)` to raise an `KeyError` if a column cannot export any value.
1415

1516
#### :floppy_disk: Change
1617

dash_json_grid/mixins.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,18 @@ def get_item_of_object(data: Any, index: Any) -> Any:
7070
return data[index[0]]
7171
elif isinstance(data, collections.abc.Sequence):
7272
index_key = index[0]
73-
return tuple(d_item.get(index_key, None) for d_item in data)
73+
_missing = object()
74+
_res = tuple(
75+
(
76+
d_item.get(index_key, _missing)
77+
if isinstance(d_item, collections.abc.Mapping)
78+
else d_item[index_key]
79+
)
80+
for d_item in data
81+
)
82+
if _res and any(val is not _missing for val in _res):
83+
return tuple((None if val is _missing else val for val in _res))
84+
raise KeyError(index_key)
7485
else:
7586
if isinstance(data, collections.abc.Mapping):
7687
return data[index]
@@ -426,7 +437,7 @@ def from_file(
426437
all_args = inspect.signature(cls).bind(*args, **kwargs).arguments.keys()
427438
if "data" in all_args:
428439
raise TypeError(
429-
'When using "json_file", it is not allowed to specify the argument '
440+
'When using "from_file", it is not allowed to specify the argument '
430441
'"data" because "data" is delegated to the argument "json_file".'
431442
)
432443
if isinstance(json_file, (str, os.PathLike)):

tests/test_init_from.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ def test_init_from_file(self, file_path: str) -> None:
8888
)
8989
log.info("Successfully initialize the component with a file-like object.")
9090

91-
with pytest.raises(TypeError, match='When using "from_str", it is not allowed'):
91+
with pytest.raises(
92+
TypeError, match='When using "from_file", it is not allowed'
93+
):
9294
dash_json_grid.DashJsonGrid.from_file(file_path, data={})
9395
log.info(
94-
'Successfully validate the functionality of using "data" with file_file(...)'
96+
'Successfully validate the functionality of using "data" with '
97+
"from_file(...)"
9598
)

0 commit comments

Comments
 (0)