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

filter method not taking key_path_separator in consideration #4

Closed
rbentaarit opened this issue Dec 23, 2019 · 5 comments
Closed

filter method not taking key_path_separator in consideration #4

rbentaarit opened this issue Dec 23, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@rbentaarit
Copy link

Python version
3.7.4

Package version
0.14.0

Current behavior (bug description)
d = benedict()
d.keypath_separator = '$'
--implementation--
print (d.keypath_separator)
d1 = d.filter(lambda k, v: True)
print (d1.keypath_separator)

$
.
This behavior makes me loose the correct structure when I have '.' in the key parameters.
Expected behavior
$
$

@rbentaarit rbentaarit added the bug Something isn't working label Dec 23, 2019
@fabiocaccamo
Copy link
Owner

Thank you for reporting this issue. The same problem affects also all methods that return a new benedict instance.
I will fix this in the next release.

@fabiocaccamo
Copy link
Owner

In the meanwhile you can fix it by doing:

d1 = benedict(d.filter(lambda k, v: True), keypath_separator=d.keypath_separator)

@rbentaarit
Copy link
Author

rbentaarit commented Dec 24, 2019

Thanks for the quick response : )
Unfortunately this will not work because the tree is already generated by the filter function and in my use case I have '.' in the keys which will divide them in sub trees before the constructor function.
so my fix for now :

 new_dict = benedict()
  new_dict.keypath_separator = '$'
  keys = list(d.keys())
  for key in keys:
    value = d.get(key, None)
    if True:  
        new_dict[key] = value
  return new_dict

@fabiocaccamo
Copy link
Owner

I understand the problem, thank you for having explained it better.

fabiocaccamo added a commit that referenced this issue Jan 7, 2020
@fabiocaccamo
Copy link
Owner

You can install 0.14.1 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants