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

utils: new function convert_to_numerical #58

Closed

Conversation

frodon1
Copy link
Contributor

@frodon1 frodon1 commented Oct 6, 2015

This new parameter allows to convert string values to numerical values.
This allow to consider 100 and '100' equal, or 100 and '101' with a tolerance parameter of 0.1 for instance.

@frodon1 frodon1 force-pushed the frodon1-new_convert_parameter branch 4 times, most recently from b118577 to a93923f Compare October 7, 2015 07:27
@frodon1 frodon1 changed the title New convert parameter diff: add convert parameter Oct 7, 2015
@jirikuncar
Copy link
Member

@frodon1 IMHO the convert parameter is a bit more controversial. Can you try to preprocess your dict before you pass it to diff function instead?

def my_convert(obj):
    if isinstance(obj, dict):
        return {key: my_convert(value) for key, value in obj.items()}
    elif isinstance(obj, (set, list)):
        return ([my_convert(value) for value in obj]
    elif isinstance(obj, str):
        return convert_to_numeric(obj)
    return obj

print(list(diff(my_convert(first), my_convert(second))))

@frodon1
Copy link
Contributor Author

frodon1 commented Oct 7, 2015

You are right, pre-processing the input dict is the right thing to do.
Actually it is what I did with my dict :).

@jirikuncar
Copy link
Member

@frodon1 😊 can you close the PR?

@frodon1 frodon1 force-pushed the frodon1-new_convert_parameter branch 2 times, most recently from 08e7df1 to 4ed886f Compare October 7, 2015 08:38
@frodon1
Copy link
Contributor Author

frodon1 commented Oct 7, 2015

I changed the PR: i completed the convert_to_numeric function, removed the convert parameter and updated the tests. Is it OK for you ?

@frodon1 frodon1 force-pushed the frodon1-new_convert_parameter branch from 4ed886f to 853f1ad Compare October 7, 2015 08:41
* NEW Adds a utility function to convert a value or the values of a list
  or a dict to numerical values.

Signed-off-by: Gilles DAVID <frodon1@gmail.com>
@frodon1 frodon1 force-pushed the frodon1-new_convert_parameter branch from 853f1ad to 34c9163 Compare October 7, 2015 08:47
@frodon1 frodon1 changed the title diff: add convert parameter utils: new function convert_to_numerical Oct 7, 2015
@frodon1
Copy link
Contributor Author

frodon1 commented Oct 7, 2015

@jirikuncar I close this PR and create another PR.

@frodon1 frodon1 closed this Oct 7, 2015
@frodon1 frodon1 deleted the frodon1-new_convert_parameter branch October 7, 2015 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants