[yt-svn] commit/yt: MatthewTurk: Merged in ngoldbaum/yt (pull request #2387)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Oct 17 15:11:07 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/34a95afc6804/
Changeset:   34a95afc6804
Branch:      yt
User:        MatthewTurk
Date:        2016-10-17 22:10:41+00:00
Summary:     Merged in ngoldbaum/yt (pull request #2387)

Don't cast ndarrays or ndarray subclasses in the ds.box implementation. Closes #1280
Affected #:  2 files

diff -r 060539ec8b44431127640887a5b93c23d5643266 -r 34a95afc68047ab60ddf5a20816dfb80291cd99b yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -781,8 +781,14 @@
         without having to specify a *center* value.  It assumes the center
         is the midpoint between the left_edge and right_edge.
         """
-        left_edge = np.array(left_edge)
-        right_edge = np.array(right_edge)
+        # we handle units in the region data object
+        # but need to check if left_edge or right_edge is a
+        # list or other non-array iterable before calculating
+        # the center
+        if not isinstance(left_edge, np.ndarray):
+            left_edge = np.array(left_edge)
+        if not isinstance(right_edge, np.ndarray):
+            right_edge = np.array(right_edge)
         c = (left_edge + right_edge)/2.0
         return self.region(c, left_edge, right_edge, **kwargs)
 

diff -r 060539ec8b44431127640887a5b93c23d5643266 -r 34a95afc68047ab60ddf5a20816dfb80291cd99b yt/data_objects/tests/test_dataset_access.py
--- a/yt/data_objects/tests/test_dataset_access.py
+++ b/yt/data_objects/tests/test_dataset_access.py
@@ -1,3 +1,5 @@
+import numpy as np
+
 from yt.testing import \
     assert_equal, \
     fake_amr_ds, \
@@ -6,6 +8,25 @@
 
 # This will test the "dataset access" method.
 
+def test_box_creation():
+    ds = fake_random_ds(32, length_unit=2)
+    left_edge = ds.arr([0.2, 0.2, 0.2], 'cm')
+    right_edge = ds.arr([0.6, 0.6, 0.6], 'cm')
+    center = (left_edge + right_edge)/2
+
+    boxes = [
+        ds.box(left_edge, right_edge),
+        ds.box(0.5*np.array(left_edge), 0.5*np.array(right_edge)),
+        ds.box((0.5*left_edge).tolist(), (0.5*right_edge).tolist())
+    ]
+
+    region = ds.region(center, left_edge, right_edge)
+
+    for b in boxes:
+        assert_equal(b.left_edge, region.left_edge)
+        assert_equal(b.right_edge, region.right_edge)
+        assert_equal(b.center, region.center)
+
 def test_region_from_d():
     ds = fake_amr_ds(fields=["density"])
     # We'll do a couple here

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the yt-svn mailing list