Skip to content

Commit

Permalink
TST: Make xarray & pandas optional test dependencies (#1335)
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 authored Aug 31, 2023
1 parent 8010602 commit 2caeb99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ macos_task:
CMAKE_OSX_ARCHITECTURES='arm64'
LDFLAGS="${LDFLAGS} -Wl,-rpath,${CIRRUS_WORKING_DIR}/pyproj/proj_dir/lib"
CIBW_BEFORE_ALL_MACOS: bash ./ci/proj-compile-wheels.sh
CIBW_TEST_REQUIRES: cython pytest oldest-supported-numpy pandas xarray
CIBW_BEFORE_TEST: python -m pip install shapely || echo "Shapely install failed"
CIBW_TEST_REQUIRES: cython pytest oldest-supported-numpy
CIBW_BEFORE_TEST: python -m pip install shapely pandas xarray || echo "Optional requirements install failed"
CIBW_TEST_COMMAND: >
pyproj -v &&
python -c "import pyproj; pyproj.Proj(init='epsg:4269')" &&
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ jobs:
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair --add-path C:/vcpkg/installed/${{ matrix.triplet }}/bin -w {dest_dir} {wheel}"
CIBW_BEFORE_ALL_LINUX: bash ./ci/proj-compile-wheels.sh
CIBW_BEFORE_ALL_MACOS: bash ./ci/proj-compile-wheels.sh
CIBW_TEST_REQUIRES: cython pytest oldest-supported-numpy pandas xarray
CIBW_BEFORE_TEST: python -m pip install shapely || echo "Shapely install failed"
CIBW_TEST_REQUIRES: cython pytest oldest-supported-numpy
CIBW_BEFORE_TEST: python -m pip install shapely pandas xarray || echo "Optional requirements install failed"
CIBW_TEST_COMMAND: >
pyproj -v &&
python -c "import pyproj; pyproj.Proj(init='epsg:4269')" &&
Expand Down
24 changes: 17 additions & 7 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import numpy
import pytest
from pandas import Series
from xarray import DataArray

from pyproj.utils import DataType, _copytobuffer, _copytobuffer_return_scalar

Expand All @@ -22,7 +20,6 @@ def test__copytobuffer_return_scalar__invalid():
"in_data, data_type",
[
(numpy.array(1), DataType.FLOAT),
(DataArray(numpy.array(1)), DataType.FLOAT),
(1, DataType.FLOAT),
([1], DataType.LIST),
((1,), DataType.TUPLE),
Expand All @@ -32,10 +29,23 @@ def test__copytobuffer(in_data, data_type):
assert _copytobuffer(in_data) == (array("d", [1]), data_type)


@pytest.mark.parametrize(
"in_arr", [numpy.array([1]), DataArray(numpy.array([1])), Series(numpy.array([1]))]
)
def test__copytobuffer__numpy_array(in_arr):
def test__copytobuffer__xarray_scalar():
xarray = pytest.importorskip("xarray")
assert _copytobuffer(xarray.DataArray(numpy.array(1))) == (
array("d", [1]),
DataType.FLOAT,
)


@pytest.mark.parametrize("arr_type", ["numpy", "xarray", "pandas"])
def test__copytobuffer__array(arr_type):
in_arr = numpy.array([1])
if arr_type == "xarray":
xarray = pytest.importorskip("xarray")
in_arr = xarray.DataArray(in_arr)
elif arr_type == "pandas":
pandas = pytest.importorskip("pandas")
in_arr = pandas.Series(in_arr)
assert _copytobuffer(in_arr) == (
in_arr.astype("d").__array__(),
DataType.ARRAY,
Expand Down

0 comments on commit 2caeb99

Please sign in to comment.