| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1498,6 +1498,10 @@ def have_units(self): | |||
| 1498 | 1498 | return self.converter is not None or self.units is not None | |
| 1499 | 1499 | ||
| 1500 | 1500 | def convert_units(self, x): | |
| 1501 | + # If x is already a number, doesn't need converting | ||
| 1502 | + if munits.ConversionInterface.is_numlike(x): | ||
| 1503 | + return x | ||
| 1504 | + | ||
| 1501 | 1505 | if self.converter is None: | |
| 1502 | 1506 | self.converter = munits.registry.get_converter(x) | |
| 1503 | 1507 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1804,8 +1804,6 @@ def convert(value, unit, axis): | |||
| 1804 | 1804 | ||
| 1805 | 1805 | The *unit* and *axis* arguments are not used. | |
| 1806 | 1806 | """ | |
| 1807 | - if units.ConversionInterface.is_numlike(value): | ||
| 1808 | - return value | ||
| 1809 | 1807 | return date2num(value) | |
| 1810 | 1808 | ||
| 1811 | 1809 | @staticmethod | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,7 +31,10 @@ def __getattr__(self, attr): | |||
| 31 | 31 | return getattr(self.magnitude, attr) | |
| 32 | 32 | ||
| 33 | 33 | def __getitem__(self, item): | |
| 34 | - return Quantity(self.magnitude[item], self.units) | ||
| 34 | + if iterable(self.magnitude): | ||
| 35 | + return Quantity(self.magnitude[item], self.units) | ||
| 36 | + else: | ||
| 37 | + return Quantity(self.magnitude, self.units) | ||
| 35 | 38 | ||
| 36 | 39 | def __array__(self): | |
| 37 | 40 | return np.asarray(self.magnitude) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments