-
Notifications
You must be signed in to change notification settings - Fork 186
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
Allow the use of percent string in Bool.__and__ method #780
Allow the use of percent string in Bool.__and__ method #780
Conversation
Thanks! Add a test and a CHANGELOG entry, please? It would be amazing if you could please look at https://github.com/opensearch-project/opensearch-api-specification as well and add tests there for this and other use-cases so we don't lose this functionality as we move towards more of this code being generated. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #780 +/- ##
==========================================
- Coverage 71.95% 70.69% -1.26%
==========================================
Files 91 105 +14
Lines 8001 8621 +620
==========================================
+ Hits 5757 6095 +338
- Misses 2244 2526 +282 ☔ View full report in Codecov by Sentry. |
1f5123a
to
7d2d368
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking pretty good, thanks for the tests. See below for comments.
Please do fix DCO, git commit --amend -s
and force push will do it.
CHANGELOG.md
Outdated
@@ -9,6 +9,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | |||
### Removed | |||
### Fixed | |||
- Fixed Search helper to ensure proper retention of the _collapse attribute in chained operations. ([#771](https://github.com/opensearch-project/opensearch-py/pull/771)) | |||
- Fixed the use of `minimum_should_match` with `Bool` to allow the use of string-based value (percent string, combination) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add PR number here.
opensearchpy/helpers/query.py
Outdated
min_should_match = qx._min_should_match | ||
|
||
# attempt to convert a string integer representation to int | ||
with contextlib.suppress(ValueError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am worried that int()
may do unexpected things like rounding a float for example.
Maybe we can just be explicit, check that the value ends with % and convert the rest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But having a float at this point is a bit of nonsense, no? Looking at the documentions, the min_should_match
mean "i need at least X values" - or did I miss something? Maybe a round up/down to the nearest should be ok? (something like: int(round(float("3.14"), 0))
-> 3
)
Indeed, I can only check for string that end up with a "%", but we'll lose the possibility to use int who has been cast as string. I let you have the final word. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you misunderstood me, sorry.
I mean that if we rely on an exception to see if the value can be converted, then we might introduce undesired behavior.
$ python -c "print(int("3.14"))"
3
You can see that if I pass a value not accepted by the API it's happily coerced into an int, losing the actual value! That doesn't seem good :) It should be an error in this case, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, get it. If an invalid value is passed to the query, we don't want to magically (attempt to) fix it. 👍
Code and test has been updated.
5f75ff9
to
79d4d8b
Compare
Signed-off-by: Godefroy Amaury de Malefète <godefroy-de-montmirail-dit-le-hardi@protonmail.com>
79d4d8b
to
b786504
Compare
Thanks for fixing this! |
…oject#780) Signed-off-by: Godefroy Amaury de Malefète <godefroy-de-montmirail-dit-le-hardi@protonmail.com>
Description
Allow the use of
50
,"50"
or"50%"
as valid value forqx._min_should_match
/min_should_match
in theBool.__and__
method.Previously, if for any reason the
qx._min_should_match
was a string, a TypeError error was raise by theif len(qx.should) <= min_should_match:
.Still raise a ValueError if the given value is an invalid integer representation.
Issues Resolved
Closes #779
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.