From aa01bfb04e91361369abab0ea52723a9a8188079 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Wed, 23 Apr 2014 15:05:28 -0400 Subject: [PATCH 1/6] a test for check_endian --- spectral_cube/tests/test_spectral_cube.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/spectral_cube/tests/test_spectral_cube.py b/spectral_cube/tests/test_spectral_cube.py index 9c666235d..cf1899432 100644 --- a/spectral_cube/tests/test_spectral_cube.py +++ b/spectral_cube/tests/test_spectral_cube.py @@ -475,3 +475,25 @@ def test_ds9region(): #region = 'circle(2,2,2)' #subcube = cube.subcube_from_ds9region(region) + +def test_endians(): + """ + Test that the endianness checking returns something in Native form + (this is only needed for non-numpy functions that worry about the + endianness of their data) + """ + big = np.array([[[1],[2]]], dtype='>f4') + lil = np.array([[[1],[2]]], dtype=' Date: Wed, 23 Apr 2014 15:07:19 -0400 Subject: [PATCH 2/6] tests to make sure check_endian = off leaves data untouched --- spectral_cube/tests/test_spectral_cube.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spectral_cube/tests/test_spectral_cube.py b/spectral_cube/tests/test_spectral_cube.py index cf1899432..514d1e152 100644 --- a/spectral_cube/tests/test_spectral_cube.py +++ b/spectral_cube/tests/test_spectral_cube.py @@ -481,6 +481,11 @@ def test_endians(): Test that the endianness checking returns something in Native form (this is only needed for non-numpy functions that worry about the endianness of their data) + + WARNING: Because the endianness is machine-dependent, this may fail on + different architectures! This is because numpy automatically converts + little-endian to native in the dtype parameter; I need a workaround for + this. """ big = np.array([[[1],[2]]], dtype='>f4') lil = np.array([[[1],[2]]], dtype='' + assert xlil.dtype.byteorder == '=' From 08899578e94282d7b76ad08c613ff877f61619a9 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 26 Aug 2014 13:39:40 +0200 Subject: [PATCH 3/6] add bottleneck installation to travis --- .travis.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 08ddb7eab..1b7db9bcd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,7 @@ env: - ASTROPY_VERSION=stable - CONDA_INSTALL='conda install -c astropy-ci-extras --yes' - PIP_INSTALL='pip install' + - BOTTLENECK=no matrix: - SETUP_CMD='egg_info' @@ -34,7 +35,7 @@ matrix: # Try Astropy development version - python: 2.7 env: ASTROPY_VERSION=development SETUP_CMD='test' - - python: 3.3 + - python: 3.4 env: ASTROPY_VERSION=development SETUP_CMD='test' # Try all python versions with the latest numpy @@ -59,6 +60,12 @@ matrix: - python: 2.7 env: NUMPY_VERSION=1.5 SETUP_CMD='test' + # Test with bottleneck + - python: 2.7 + env: ASTROPY_VERSION=stable SETUP_CMD='test' bottleneck=yes NUMPY_VERSION=1.8 + - python: 3.4 + env: ASTROPY_VERSION=stable SETUP_CMD='test' bottleneck=yes NUMPY_VERSION=1.8 + before_install: # Use utf8 encoding. Should be default, but this is insurance against @@ -90,6 +97,9 @@ install: # YT - if [[ $SETUP_CMD != egg_info ]] && [[ $TRAVIS_PYTHON_VERSION == 2.7 ]] && [[ $NUMPY_VERSION == 1.8 ]]; then $CONDA_INSTALL numpy=$NUMPY_VERSION yt; fi + # Bottleneck + - if [[ $SETUP_CMD != egg_info ]] && [[ $BOTTLENECK == yes ]] && [[ $NUMPY_VERSION == 1.8 ]]; then $CONDA_INSTALL --channel https://conda.binstar.org/public bottleneck; fi + # OPTIONAL DEPENDENCIES # Here you can add any dependencies your package may have. You can use # conda for packages available through conda, or pip for any other From 65d1d02bdffee3507144f1615fd52d8c847bfa76 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 26 Aug 2014 13:41:33 +0200 Subject: [PATCH 4/6] skip bottleneck tests if bottleneck not imported --- spectral_cube/tests/test_spectral_cube.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spectral_cube/tests/test_spectral_cube.py b/spectral_cube/tests/test_spectral_cube.py index 514d1e152..73eb58162 100644 --- a/spectral_cube/tests/test_spectral_cube.py +++ b/spectral_cube/tests/test_spectral_cube.py @@ -22,6 +22,12 @@ yt_version = StrictVersion('0.0.0') ytOK = False +try: + import bottleneck + bottleneckOK = True +except ImportError: + bottleneckOK = False + def cube_and_raw(filename): p = path(filename) @@ -476,6 +482,7 @@ def test_ds9region(): #region = 'circle(2,2,2)' #subcube = cube.subcube_from_ds9region(region) +@pytest.mark.skipif(not bottleneckOK, reason='Bottleneck could not be imported') def test_endians(): """ Test that the endianness checking returns something in Native form From 96e6457e1925adc02853f178c8b235fe9b5ea1fe Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 26 Aug 2014 13:44:11 +0200 Subject: [PATCH 5/6] change version of bottleneck to install --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1b7db9bcd..031287af6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -98,7 +98,8 @@ install: - if [[ $SETUP_CMD != egg_info ]] && [[ $TRAVIS_PYTHON_VERSION == 2.7 ]] && [[ $NUMPY_VERSION == 1.8 ]]; then $CONDA_INSTALL numpy=$NUMPY_VERSION yt; fi # Bottleneck - - if [[ $SETUP_CMD != egg_info ]] && [[ $BOTTLENECK == yes ]] && [[ $NUMPY_VERSION == 1.8 ]]; then $CONDA_INSTALL --channel https://conda.binstar.org/public bottleneck; fi + # asmeurer currently (8/26/2014) supports numpy 1.8 + - if [[ $SETUP_CMD != egg_info ]] && [[ $BOTTLENECK == yes ]] && [[ $NUMPY_VERSION == 1.8 ]]; then $CONDA_INSTALL --channel https://conda.binstar.org/asmeurer bottleneck; fi # OPTIONAL DEPENDENCIES # Here you can add any dependencies your package may have. You can use From cd936b7348b87c25b86b50e654e06691215ab938 Mon Sep 17 00:00:00 2001 From: "Adam Ginsburg (keflavich)" Date: Tue, 26 Aug 2014 13:47:22 +0200 Subject: [PATCH 6/6] fix a ridiculously silly bug in which the computed result wasn't returned --- spectral_cube/spectral_cube.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spectral_cube/spectral_cube.py b/spectral_cube/spectral_cube.py index 99a0818cb..10c5149f8 100644 --- a/spectral_cube/spectral_cube.py +++ b/spectral_cube/spectral_cube.py @@ -602,7 +602,9 @@ def median(self, axis=None, **kwargs): projection=True, check_endian=True, **kwargs) except ImportError: - return self.apply_function(np.median, axis=axis, **kwargs) + result = self.apply_function(np.median, axis=axis, **kwargs) + + return result def percentile(self, q, axis=None, **kwargs): """