Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b1ae81c

Browse filesBrowse files
authored
Merge pull request #14573 from anntzer/jpl
MNT: Cleanup jpl_units.
2 parents d68ea83 + af534c1 commit b1ae81c
Copy full SHA for b1ae81c

File tree

Expand file treeCollapse file tree

7 files changed

+30
-34
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+30
-34
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecations
2+
````````````
3+
4+
``testing.jpl_units.UnitDbl.UnitDbl.checkUnits`` is deprecated.

‎lib/matplotlib/testing/jpl_units/Duration.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/jpl_units/Duration.py
+7-9Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import operator
44

5+
from matplotlib import cbook
6+
57

68
class Duration:
79
"""Class Duration in development.
@@ -18,11 +20,7 @@ def __init__(self, frame, seconds):
1820
- frame The frame of the duration. Must be 'ET' or 'UTC'
1921
- seconds The number of seconds in the Duration.
2022
"""
21-
if frame not in self.allowed:
22-
msg = "Input frame '%s' is not one of the supported frames of %s" \
23-
% (frame, str(self.allowed))
24-
raise ValueError(msg)
25-
23+
cbook._check_in_list(self.allowed, frame=frame)
2624
self._frame = frame
2725
self._seconds = seconds
2826

@@ -176,7 +174,7 @@ def checkSameFrame(self, rhs, func):
176174
- func The name of the function doing the check.
177175
"""
178176
if self._frame != rhs._frame:
179-
msg = "Cannot %s Duration's with different frames.\n" \
180-
"LHS: %s\n" \
181-
"RHS: %s" % (func, self._frame, rhs._frame)
182-
raise ValueError(msg)
177+
raise ValueError(
178+
f"Cannot {func} Durations with different frames.\n"
179+
f"LHS: {self._frame}\n"
180+
f"RHS: {rhs._frame}")

‎lib/matplotlib/testing/jpl_units/Epoch.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/jpl_units/Epoch.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import operator
44
import math
55
import datetime as DT
6+
7+
from matplotlib import cbook
68
from matplotlib.dates import date2num
79

810

@@ -56,11 +58,7 @@ def __init__(self, frame, sec=None, jd=None, daynum=None, dt=None):
5658
"dnum= %s\n"
5759
"dt = %s" % (sec, jd, daynum, dt))
5860

59-
if frame not in self.allowed:
60-
raise ValueError(
61-
"Input frame '%s' is not one of the supported frames of %s" %
62-
(frame, list(self.allowed.keys())))
63-
61+
cbook._check_in_list(self.allowed, frame=frame)
6462
self._frame = frame
6563

6664
if dt is not None:

‎lib/matplotlib/testing/jpl_units/EpochConverter.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/jpl_units/EpochConverter.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ def convert(value, unit, axis):
9999

100100
if not cbook.is_scalar_or_string(value):
101101
return [EpochConverter.convert(x, unit, axis) for x in value]
102-
if (units.ConversionInterface.is_numlike(value)
103-
and not isinstance(value, (U.Epoch, U.Duration))):
102+
if units.ConversionInterface.is_numlike(value):
104103
return value
105104
if unit is None:
106105
unit = EpochConverter.default_units(value, axis)

‎lib/matplotlib/testing/jpl_units/UnitDbl.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/jpl_units/UnitDbl.py
+12-15Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import operator
44

5+
from matplotlib import cbook
6+
57

68
class UnitDbl:
79
"""Class UnitDbl in development.
@@ -45,8 +47,7 @@ def __init__(self, value, units):
4547
- value The numeric value of the UnitDbl.
4648
- units The string name of the units the value is in.
4749
"""
48-
self.checkUnits(units)
49-
50+
cbook._check_in_list(self.allowed, units=units)
5051
data = self.allowed[units]
5152
self._value = float(value * data[0])
5253
self._units = data[1]
@@ -66,17 +67,13 @@ def convert(self, units):
6667
"""
6768
if self._units == units:
6869
return self._value
69-
70-
self.checkUnits(units)
71-
70+
cbook._check_in_list(self.allowed, units=units)
7271
data = self.allowed[units]
7372
if self._units != data[1]:
74-
msg = "Error trying to convert to different units.\n" \
75-
" Invalid conversion requested.\n" \
76-
" UnitDbl: %s\n" \
77-
" Units: %s\n" % (str(self), units)
78-
raise ValueError(msg)
79-
73+
raise ValueError(f"Error trying to convert to different units.\n"
74+
f" Invalid conversion requested.\n"
75+
f" UnitDbl: {self}\n"
76+
f" Units: {units}\n")
8077
return self._value / data[0]
8178

8279
def __abs__(self):
@@ -236,6 +233,7 @@ def range(start, stop, step=None):
236233

237234
return elems
238235

236+
@cbook.deprecated("3.2")
239237
def checkUnits(self, units):
240238
"""Check to see if some units are valid.
241239
@@ -262,7 +260,6 @@ def checkSameUnits(self, rhs, func):
262260
- func The name of the function doing the check.
263261
"""
264262
if self._units != rhs._units:
265-
msg = "Cannot %s units of different types.\n" \
266-
"LHS: %s\n" \
267-
"RHS: %s" % (func, self._units, rhs._units)
268-
raise ValueError(msg)
263+
raise ValueError(f"Cannot {func} units of different types.\n"
264+
f"LHS: {self._units}\n"
265+
f"RHS: {rhs._units}")

‎lib/matplotlib/testing/jpl_units/UnitDblConverter.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/jpl_units/UnitDblConverter.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ def convert(value, unit, axis):
8686

8787
if not cbook.is_scalar_or_string(value):
8888
return [UnitDblConverter.convert(x, unit, axis) for x in value]
89-
# If the incoming value behaves like a number, but is not a UnitDbl,
89+
# If the incoming value behaves like a number,
9090
# then just return it because we don't know how to convert it
9191
# (or it is already converted)
92-
if (units.ConversionInterface.is_numlike(value)
93-
and not isinstance(value, U.UnitDbl)):
92+
if units.ConversionInterface.is_numlike(value):
9493
return value
9594
# If no units were specified, then get the default units to use.
9695
if unit is None:

‎lib/matplotlib/units.py

Copy file name to clipboardExpand all lines: lib/matplotlib/units.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class ConversionInterface:
112112
The minimal interface for a converter to take custom data types (or
113113
sequences) and convert them to values Matplotlib can use.
114114
"""
115+
115116
@staticmethod
116117
def axisinfo(unit, axis):
117118
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.