MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / Quantity

Class Quantity

lib/matplotlib/tests/test_units.py:16–44  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15# Basic class that wraps numpy array and has units
16class Quantity:
17 def __init__(self, data, units):
18 self.magnitude = data
19 self.units = units
20
21 def to(self, new_units):
22 factors = {('hours', 'seconds'): 3600, ('minutes', 'hours'): 1 / 60,
23 ('minutes', 'seconds'): 60, ('feet', 'miles'): 1 / 5280.,
24 ('feet', 'inches'): 12, ('miles', 'inches'): 12 * 5280}
25 if self.units != new_units:
26 mult = factors[self.units, new_units]
27 return Quantity(mult * self.magnitude, new_units)
28 else:
29 return Quantity(self.magnitude, self.units)
30
31 def __copy__(self):
32 return Quantity(self.magnitude, self.units)
33
34 def __getattr__(self, attr):
35 return getattr(self.magnitude, attr)
36
37 def __getitem__(self, item):
38 if np.iterable(self.magnitude):
39 return Quantity(self.magnitude[item], self.units)
40 else:
41 return Quantity(self.magnitude, self.units)
42
43 def __array__(self):
44 return np.asarray(self.magnitude)
45
46
47@pytest.fixture

Callers 9

toMethod · 0.85
__copy__Method · 0.85
__getitem__Method · 0.85
convertFunction · 0.85
test_numpy_facadeFunction · 0.85
test_plot_masked_unitsFunction · 0.85

Calls

no outgoing calls

Tested by 9

toMethod · 0.68
__copy__Method · 0.68
__getitem__Method · 0.68
convertFunction · 0.68
test_numpy_facadeFunction · 0.68
test_plot_masked_unitsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…