-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Description
Environment
- Python version: 3.11.11
- jdiff version: 0.0.6
Expected Behavior
I expect to be able to send in a list of dicts for data when using exclude with extract_data_from_json and it properly parses through the list of dicts.
Observed Behavior
exclude only removes keys when data is a dict:
Lines 33 to 37 in be82cec
| if exclude and isinstance(data, Dict): | |
| if not isinstance(exclude, list): | |
| raise ValueError(f"Exclude list must be defined as a list. You have {type(exclude)}") | |
| # exclude unwanted elements | |
| exclude_filter(data, exclude) |
Despite that the underlying exclude_filter works recursively with lists:
jdiff/jdiff/utils/data_normalization.py
Lines 79 to 82 in be82cec
| elif isinstance(data, list): | |
| for element in data: | |
| if isinstance(element, (dict, list)): | |
| exclude_filter(element, exclude) |
Steps to Reproduce
Here, you can see it works when sending in a dict rather than a list:
In [1]: from jdiff import extract_data_from_json
In [2]: data = [{"foo": 1, "bar": 2}]
In [3]: extract_data_from_json(data, exclude=["bar"])
Out[3]: [{'foo': 1, 'bar': 2}]
In [4]: extract_data_from_json(data[0], exclude=["bar"])
Out[4]: {'foo': 1}But, if you send the list from before to exclude_filter it works as expected:
In [1]: from jdiff.utils.data_normalization import exclude_filter
In [2]: data = [{"foo": 1, "bar": 2}]
In [3]: exclude_filter(data, exclude=["bar"])
In [4]: data
Out[4]: [{'foo': 1}]Metadata
Metadata
Assignees
Labels
No labels