GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [MNT]: Implement `Scale.val_in_range` and refactor `_point_in_data_domain` by null-dreams · Pull Request #31306 · matplotlib/matplotlib Conversation
|
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. You can also join us on gitter for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I would like some advice regarding implementing tests for the added function |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Scale.val_in_range and refactor _point_in_data_domain
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Your type usage is mixed up. In _pint_in_data_domain we just need a bool. You implementations return arrays. Your type stub claims bool | array return type. Since we only need single values, let's keep it simple and only implement that. We can always expand later.
Concerning tests: Write tests for all implemented subclasses. Consider edge cases like Inf and NaN
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| """ | ||
| return self._scale.limit_range_for_scale(vmin, vmax, self.get_minpos()) | ||
|
|
||
| def val_in_range(self, val): |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation to expose this on the Axis?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I noticed limit_range_in_scale being available in Axis class, so exposing the val_in_range seemed consistent to me. But I later forgot to implement the wrapper in _point_in_data_domain.
I have two possible approaches here:
_point_in_data_domain._point_in_data_domain, using the _scale attribute, unchanged.After going through other exposed apis, I feel removing the wrapper here would be fine as currently there is no other use of val_in_range except in _point_in_data_domain.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Return whether the value(s) are within the valid range for this scale. | ||
| """ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| Return whether the value(s) are within the valid range for this scale. | |
| """ | |
| Return whether the value(s) are within the valid range for this scale. | |
| This method is a generic implementation. Subclasses may implement | |
| more efficent solutions for their domain. | |
| """ |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| """ | ||
| Return `True` for all values. | ||
| """ |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The docstring should always descripe the concept, not just the imlementation. A docstring
def some_func(): """Return True.""" return True
has zero information conent.
Instead do:
| """ | |
| Return `True` for all values. | |
| """ | |
| """ | |
| Return whether the value(s) are within the valid range for this scale. | |
| This is True for all inputs. | |
| """ |
The first sentence should be in all val_in_range docs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This was actually pretty enlightening. Kind of changed the way I thought about docstrings.
I'm making the needed changes. Thank you very much for the suggestion.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've made the changes which I think should fix the type ambiguity I caused earlier. I will need a little time to implement the tests as I have never written tests before and will need to study the current tests before I can implement mine and fix all the linting error with it as well. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
While working on this I noticed a couple of behaviors that I wanted to clarify. For Example code: from matplotlib.scale import LinearScale s = LinearScale(axis=None) vmin, vmax = s.limit_range_for_scale(float('nan'), float('nan'), minpos=1e-100) print(vmin, vmax) which results in Similarly for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This is a difficult question. Without having looked into this, I suspect, one of the two is correct:
Which one it is needs to be found out by looking at the current usage contexts. In either case, the behavior should be specified. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thinking about it, the primary use for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have added the finite bound check for the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| if not math.isfinite(val): | ||
| return False | ||
| else: | ||
| return val > 0 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same logic, but more compact.
| if not math.isfinite(val): | |
| return False | |
| else: | |
| return val > 0 | |
| return math.isfinite(val) and val > 0 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks @null-dreams! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[MNT]: Scaleval_in_range method
There was an error while loading. Please reload this page.