-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
[MNT]: Implement Scale.val_in_range and refactor _point_in_data_domain
#31306
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
Changes from 11 commits
c3df005
f91d2b4
926c259
e3dc7b7
6feeec1
631a52f
d62a69f
59bd52b
6d03949
b78b003
3de6b1f
c35268f
6b820a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |||||||||||||||||
| from functools import wraps | ||||||||||||||||||
|
|
||||||||||||||||||
| import numpy as np | ||||||||||||||||||
| import math | ||||||||||||||||||
|
|
||||||||||||||||||
| import matplotlib as mpl | ||||||||||||||||||
| from matplotlib import _api, _docstring | ||||||||||||||||||
|
|
@@ -114,6 +115,22 @@ def limit_range_for_scale(self, vmin, vmax, minpos): | |||||||||||||||||
| """ | ||||||||||||||||||
| return vmin, vmax | ||||||||||||||||||
|
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return whether the value(s) are within the valid range for this scale. | ||||||||||||||||||
|
|
||||||||||||||||||
| This method is a generic implementation. Subclasses may implement more | ||||||||||||||||||
| efficient solutions for their domain. | ||||||||||||||||||
| """ | ||||||||||||||||||
| try: | ||||||||||||||||||
| if not math.isfinite(val): | ||||||||||||||||||
| return False | ||||||||||||||||||
| else: | ||||||||||||||||||
| vmin, vmax = self.limit_range_for_scale(val, val, minpos=1e-300) | ||||||||||||||||||
| return vmin == val and vmax == val | ||||||||||||||||||
| except (TypeError, ValueError): | ||||||||||||||||||
| return False | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| def _make_axis_parameter_optional(init_func): | ||||||||||||||||||
| """ | ||||||||||||||||||
|
|
@@ -196,6 +213,14 @@ def get_transform(self): | |||||||||||||||||
| """ | ||||||||||||||||||
| return IdentityTransform() | ||||||||||||||||||
|
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return whether the value is within the valid range for this scale. | ||||||||||||||||||
|
|
||||||||||||||||||
| This is True for all values, except +-inf and NaN. | ||||||||||||||||||
| """ | ||||||||||||||||||
|
Comment on lines
+217
to
+221
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Truehas zero information conent. Instead do:
Suggested change
The first sentence should be in all
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||||||||||||||
| return math.isfinite(val) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class FuncTransform(Transform): | ||||||||||||||||||
| """ | ||||||||||||||||||
|
|
@@ -400,6 +425,17 @@ def limit_range_for_scale(self, vmin, vmax, minpos): | |||||||||||||||||
| return (minpos if vmin <= 0 else vmin, | ||||||||||||||||||
| minpos if vmax <= 0 else vmax) | ||||||||||||||||||
|
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return whether the value is within the valid range for this scale. | ||||||||||||||||||
|
|
||||||||||||||||||
| This is True for value(s) > 0 except +inf. | ||||||||||||||||||
|
QuLogic marked this conversation as resolved.
Outdated
|
||||||||||||||||||
| """ | ||||||||||||||||||
| if not math.isfinite(val): | ||||||||||||||||||
| return False | ||||||||||||||||||
| else: | ||||||||||||||||||
| return val > 0 | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same logic, but more compact.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class FuncScaleLog(LogScale): | ||||||||||||||||||
| """ | ||||||||||||||||||
|
|
@@ -581,6 +617,14 @@ def get_transform(self): | |||||||||||||||||
| """Return the `.SymmetricalLogTransform` associated with this scale.""" | ||||||||||||||||||
| return self._transform | ||||||||||||||||||
|
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return whether the value is within the valid range for this scale. | ||||||||||||||||||
|
|
||||||||||||||||||
| This is True for all values, except +-inf and NaN. | ||||||||||||||||||
| """ | ||||||||||||||||||
| return math.isfinite(val) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class AsinhTransform(Transform): | ||||||||||||||||||
| """Inverse hyperbolic-sine transformation used by `.AsinhScale`""" | ||||||||||||||||||
|
|
@@ -707,6 +751,14 @@ def set_default_locators_and_formatters(self, axis): | |||||||||||||||||
| else: | ||||||||||||||||||
| axis.set_major_formatter('{x:.3g}') | ||||||||||||||||||
|
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return whether the value is within the valid range for this scale. | ||||||||||||||||||
|
|
||||||||||||||||||
| This is True for all values, except +-inf and NaN. | ||||||||||||||||||
| """ | ||||||||||||||||||
| return math.isfinite(val) | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| class LogitTransform(Transform): | ||||||||||||||||||
| input_dims = output_dims = 1 | ||||||||||||||||||
|
|
@@ -820,6 +872,14 @@ def limit_range_for_scale(self, vmin, vmax, minpos): | |||||||||||||||||
| return (minpos if vmin <= 0 else vmin, | ||||||||||||||||||
| 1 - minpos if vmax >= 1 else vmax) | ||||||||||||||||||
|
|
||||||||||||||||||
| def val_in_range(self, val): | ||||||||||||||||||
| """ | ||||||||||||||||||
| Return whether the value is within the valid range for this scale. | ||||||||||||||||||
|
|
||||||||||||||||||
| This is True for value(s) which are between 0 and 1 (excluded). | ||||||||||||||||||
| """ | ||||||||||||||||||
| return (val > 0) and (val < 1) | ||||||||||||||||||
|
QuLogic marked this conversation as resolved.
Outdated
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| _scale_mapping = { | ||||||||||||||||||
| 'linear': LinearScale, | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.