From 2078daa9bc5189c95f0a1f86d2e8a449505ecb49 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 18 Feb 2021 00:05:22 -0500 Subject: [PATCH 1/3] Fix example's BasicUnit array conversion. A unit is a scalar, not a length-1 array. Though `BasicUnit` implements `__rmul__`, if multiplying by an array, the NumPy implementation will call `__array__` instead. If the LHS is an array, everything is fine, but if the LHS is a scalar, the previous code would incorrectly cause it to be upcast to a 1D array. When `__getitem__` was added in #19415, `np.atleast_1d` started iterating each (now 1D, not scalar) `TaggedValue`, seeing it was length 1, and made the x/y arrays into (N, 1) instead of (N,). --- examples/units/basic_units.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index 0e62db1233e6..93fa79d19bec 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -218,7 +218,7 @@ def __array_wrap__(self, array, context): return TaggedValue(array, self) def __array__(self, t=None, context=None): - ret = np.array([1]) + ret = np.array(1) if t is not None: return ret.astype(t) else: From 9038b45d1ba2ef53c84a1c81a8f1883e1240464f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 18 Feb 2021 19:15:36 -0500 Subject: [PATCH 2/3] ci: Install Python dependencies in one go on Circle. --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 838e11c84b37..e70b1befe053 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -67,8 +67,9 @@ commands: - run: name: Install Python dependencies command: | - python -m pip install --user numpy<< parameters.numpy_version >> codecov coverage - python -m pip install --user -r requirements/doc/doc-requirements.txt + python -m pip install --user \ + numpy<< parameters.numpy_version >> codecov coverage \ + -r requirements/doc/doc-requirements.txt mpl-install: steps: From 3488dc7764c32bff3550d740302d471a83fb0430 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 25 Mar 2021 04:18:01 -0400 Subject: [PATCH 3/3] DOC: Only define __getitem__ on NumPy 1.20+. On older versions (1.18), this breaks things, so must be skipped. --- examples/units/basic_units.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index 93fa79d19bec..727b538ec183 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -5,6 +5,7 @@ """ +from distutils.version import LooseVersion import math import numpy as np @@ -154,8 +155,9 @@ def __str__(self): def __len__(self): return len(self.value) - def __getitem__(self, key): - return TaggedValue(self.value[key], self.unit) + if LooseVersion(np.__version__) >= '1.20': + def __getitem__(self, key): + return TaggedValue(self.value[key], self.unit) def __iter__(self): # Return a generator expression rather than use `yield`, so that pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy