Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to filter multiple times? #68

Open
guilhermecgs opened this issue Apr 2, 2018 · 6 comments
Open

Is it possible to filter multiple times? #68

guilhermecgs opened this issue Apr 2, 2018 · 6 comments

Comments

@guilhermecgs
Copy link

[{'signal_name': 's111',
'op_cond': [
	 {'name': 'op1',
		 'duration': 1,
		 'properties': [
			{'type': 't0', 'param0': 1}]},
	 {'name': 'op2',
		 'duration': 2,
		 'properties': [
			{'type': 't1', 'param1': 1, 'param2': 10},
			{'type': 't1', 'param1': 2, 'param2': 11}]}
			]},
{'signal_name': 's222',
'op_cond': [
	 {'name': 'op1',
		 'duration': 1,
		 'properties': [
			{'type': 't0', 'param0': 1}]},
	 {'name': 'op2',
		 'duration': 2,
		 'properties': [
			{'type': 't1', 'param1': 1, 'param2': 10},
			{'type': 't1', 'param1': 2, 'param2': 11}]}
			]}]

lets say I want all duration values from (signal_name == 's222') and (name = op2).
Is it possible to do with a one line command?

Could not figure it out reading the docs...

@guilhermecgs
Copy link
Author

Also, it is not possible to search lists

`dpath.util.values(mydata, '*/signal_name')

it gives error in :

    def _search_view(obj, glob, separator, afilter, dirs):
        view = {}
        globlist = __safe_path__(glob, separator)
        for path in _inner_search(obj, globlist, separator, dirs=dirs):
            try:
                val = dpath.path.get(obj, path, afilter=afilter, view=True)
                merge(view, val)
            except dpath.exceptions.FilteredValue:
                pass
        return view

cannot concatenate dict and list

@akesterson akesterson added the 2.0 label Dec 27, 2019
@akesterson
Copy link
Collaborator

Re dpath.util.values, the example you posted works when tested against 1.5.0:

>>> signals = [{'signal_name': 's111',
... 'op_cond': [
...      {'name': 'op1',
...              'duration': 1,
...              'properties': [
...                     {'type': 't0', 'param0': 1}]},
...      {'name': 'op2',
...              'duration': 2,
...              'properties': [
...                     {'type': 't1', 'param1': 1, 'param2': 10},
...                     {'type': 't1', 'param1': 2, 'param2': 11}]}
...                     ]},
... {'signal_name': 's222',
... 'op_cond': [
...      {'name': 'op1',
...              'duration': 1,
...              'properties': [
...                     {'type': 't0', 'param0': 1}]},
...      {'name': 'op2',
...              'duration': 2,
...              'properties': [
...                     {'type': 't1', 'param1': 1, 'param2': 10},
...                     {'type': 't1', 'param1': 2, 'param2': 11}]}
...                     ]}]
>>> import dpath.util
>>> dpath.util.values(signals, "*/signal_name")
['s111', 's222']
>>>

@calebcase
Copy link
Collaborator

Also works in 2.0.

@calebcase
Copy link
Collaborator

@guilhermecgs What version did the values error occur in?

@calebcase
Copy link
Collaborator

For the original ask, the filtering is too limited to accomplish what you are trying to do in one go. The filter callback would need to be passed more information and be able to mutate the subchild view of the walk. This would be a neat enhancement.

@akesterson
Copy link
Collaborator

Neat enhancement, but blocked by #136

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants