deepdiff icon indicating copy to clipboard operation
deepdiff copied to clipboard

Modify parent of a DeepSearch result

Open lyz-code opened this issue 3 years ago • 1 comments

I want to be able to do operations on the parent of a DeepSearch result.

I've tried with the extract function, but it returns the value of the matched path.

It would be awesome to be able to run .up() in the path result, much like the tree view in DeepDiff, so you obtain the parent object.

A solution I can think of is converting the path returned by DeepSearch in a Path object insetad of a str. This object could have these methods:

  • up(): Move up to the parent node.
  • down(): Move down to the child node.
  • path(): Get the path to the current node.

Another solution would be that extract is able to extract the parent of the matching value, though I think the first solution will be more powerful in other use cases.

Thanks for the awesome library :)

lyz-code avatar Sep 04 '20 09:09 lyz-code

Interesting. This is gonna be tricky though since when traversing an object you can have multiple children so .down() won’t know know which one to go to. Technically an object can have multiple parents too. So I think modifying the path and using extract might be the way to go. Thanks,

Sep Dehpour

On Sep 4, 2020, at 3:29 AM, lyz-code [email protected] wrote:

 I want to be able to do operations on the parent of a DeepSearch result.

I've tried with the extract function, but it returns the value of the matched path.

It would be awesome to be able to run .up() in the path result, much like the tree view in DeepDiff, so you obtain the parent object.

A solution I can think of is converting the path returned by DeepSearch in a Path object insetad of a str. This object could have these methods:

up(): Move up to the parent node. down(): Move down to the child node. path(): Get the path to the current node. Another solution would be that extract is able to extract the parent of the matching value, though I think the first solution will be more powerful in other use cases.

Thanks for the awesome library :)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

seperman avatar Sep 04 '20 20:09 seperman