Skip to content

Commit

Permalink
0.3.4 - fix get_data_by_route
Browse files Browse the repository at this point in the history
Fix: Add extra rules to `DashJsonGrid.get_data_by_route(...)` to raise an `KeyError` if a column cannot export any value.
  • Loading branch information
cainmagi committed Oct 20, 2024
1 parent d5e35e4 commit 4423ac1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

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.
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.
3. Fix: Correct typos in the docstrings of `mixins`.
3. Fix: Correct typos in the docstrings of `mixins` and `pytest`.
4. Fix: Add extra rules to `DashJsonGrid.get_data_by_route(...)` to raise an `KeyError` if a column cannot export any value.

#### :floppy_disk: Change

Expand Down
15 changes: 13 additions & 2 deletions dash_json_grid/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@ def get_item_of_object(data: Any, index: Any) -> Any:
return data[index[0]]
elif isinstance(data, collections.abc.Sequence):
index_key = index[0]
return tuple(d_item.get(index_key, None) for d_item in data)
_missing = object()
_res = tuple(
(
d_item.get(index_key, _missing)
if isinstance(d_item, collections.abc.Mapping)
else d_item[index_key]
)
for d_item in data
)
if _res and any(val is not _missing for val in _res):
return tuple((None if val is _missing else val for val in _res))
raise KeyError(index_key)
else:
if isinstance(data, collections.abc.Mapping):
return data[index]
Expand Down Expand Up @@ -426,7 +437,7 @@ def from_file(
all_args = inspect.signature(cls).bind(*args, **kwargs).arguments.keys()
if "data" in all_args:
raise TypeError(
'When using "json_file", it is not allowed to specify the argument '
'When using "from_file", it is not allowed to specify the argument '
'"data" because "data" is delegated to the argument "json_file".'
)
if isinstance(json_file, (str, os.PathLike)):
Expand Down
7 changes: 5 additions & 2 deletions tests/test_init_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ def test_init_from_file(self, file_path: str) -> None:
)
log.info("Successfully initialize the component with a file-like object.")

with pytest.raises(TypeError, match='When using "from_str", it is not allowed'):
with pytest.raises(
TypeError, match='When using "from_file", it is not allowed'
):
dash_json_grid.DashJsonGrid.from_file(file_path, data={})
log.info(
'Successfully validate the functionality of using "data" with file_file(...)'
'Successfully validate the functionality of using "data" with '
"from_file(...)"
)

0 comments on commit 4423ac1

Please sign in to comment.