From 3ed0f7be11a849b88e4bbcd9b1c707f7fef04eca Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Wed, 10 Jan 2018 11:24:28 -0600 Subject: [PATCH 1/3] add a special case for array scalars in YTArray.__str__ --- yt/units/yt_array.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yt/units/yt_array.py b/yt/units/yt_array.py index 76ebfe30e56..5927fe1345d 100644 --- a/yt/units/yt_array.py +++ b/yt/units/yt_array.py @@ -529,7 +529,11 @@ def __str__(self): """ """ - return super(YTArray, self).__str__()+' '+self.units.__str__() + # need to check if we're dealing with a scalar to avoid a recursion + # error on NumPy 1.14 and newer + if self.shape != (): + return super(YTArray, self).__str__()+' '+self.units.__str__() + return str(np.asarray(self)) + ' ' + str(self.units) # # Start unit conversion methods From 627b6a2adb906f70217bfb01ab22079394bd9664 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Wed, 10 Jan 2018 12:48:24 -0600 Subject: [PATCH 2/3] fix failing ufunc test --- yt/units/tests/test_ytarray.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/yt/units/tests/test_ytarray.py b/yt/units/tests/test_ytarray.py index 1081bd7b747..121f71fde1e 100644 --- a/yt/units/tests/test_ytarray.py +++ b/yt/units/tests/test_ytarray.py @@ -815,7 +815,8 @@ def unary_ufunc_comparison(ufunc, a): elif ufunc is np.invert: assert_raises(TypeError, ufunc, a) elif hasattr(np, 'isnat') and ufunc is np.isnat: - assert_raises(ValueError, ufunc, a) + # numpy 1.13 raises ValueError, numpy 1.14 and newer raise TypeError + assert_raises((TypeError, ValueError), ufunc, a) else: # There shouldn't be any untested ufuncs. assert_true(False) From 135d875a20630c0c62fd844f92625f54279bae0d Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Wed, 10 Jan 2018 15:07:30 -0600 Subject: [PATCH 3/3] avoid if statement --- yt/units/yt_array.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/yt/units/yt_array.py b/yt/units/yt_array.py index 5927fe1345d..7ec60c797cf 100644 --- a/yt/units/yt_array.py +++ b/yt/units/yt_array.py @@ -529,11 +529,7 @@ def __str__(self): """ """ - # need to check if we're dealing with a scalar to avoid a recursion - # error on NumPy 1.14 and newer - if self.shape != (): - return super(YTArray, self).__str__()+' '+self.units.__str__() - return str(np.asarray(self)) + ' ' + str(self.units) + return str(self.view(np.ndarray)) + ' ' + str(self.units) # # Start unit conversion methods