Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove xarray as hard dependency #629

Merged
merged 5 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/310-oldest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
- requests=2.27
- scipy=1.8
- shapely=2.0.1
- xarray=2022.3
# testing
- codecov
- matplotlib>=3.6
Expand All @@ -29,6 +28,7 @@ dependencies:
- scikit-learn=1.1
- sqlalchemy=2.0
- zstd
- xarray=2022.3
- pip
- pip:
- platformdirs==2.0.2
2 changes: 1 addition & 1 deletion ci/310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
- requests
- scipy
- shapely
- xarray
# testing
- codecov
- matplotlib
Expand All @@ -28,4 +27,5 @@ dependencies:
- pyarrow
- scikit-learn
- sqlalchemy
- xarray
- zstd
2 changes: 1 addition & 1 deletion ci/311.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
- requests
- scipy
- shapely
- xarray
# testing
- codecov
- matplotlib
Expand All @@ -28,4 +27,5 @@ dependencies:
- pyarrow
- scikit-learn
- sqlalchemy
- xarray
- zstd
1 change: 0 additions & 1 deletion ci/312-no-optional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies:
- platformdirs
- requests
- scipy
- xarray
# testing
- codecov
- matplotlib
Expand Down
2 changes: 1 addition & 1 deletion ci/312.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies:
- requests
- scipy
- shapely
- xarray
# testing
- codecov
- matplotlib
Expand All @@ -29,6 +28,7 @@ dependencies:
- scikit-learn
- sqlalchemy
- zstd
- xarray
# for docs build action (this env only)
- mkdocs-jupyter
- myst-parser
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dependencies:
- requests
- scipy
- shapely
- xarray
# optional libpysal deps
- geodatasets
- joblib
Expand All @@ -25,4 +24,5 @@ dependencies:
- pyarrow
- scikit-learn
- sqlalchemy
- xarray
- zstd
18 changes: 14 additions & 4 deletions libpysal/weights/tests/test_contiguity.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# ruff: noqa: N815

import numpy as np
import pytest

from ... import examples as pysal_examples
from ...io import geotable as pdio
from ...io.fileio import FileIO as ps_open
from ...io.fileio import FileIO
from .. import contiguity as c
from .. import raster, util
from .. import util
from ..weights import W


class ContiguityMixin:
polygon_path = pysal_examples.get_path("columbus.shp")
point_path = pysal_examples.get_path("baltim.shp")
da = raster.testDataArray((1, 4, 4), missing_vals=False)
f = ps_open(polygon_path) # our file handler
f = FileIO(polygon_path) # our file handler
polygons = f.read() # our iterable
f.seek(0) # go back to head of file
cls = object # class constructor
Expand All @@ -25,6 +27,12 @@ class ContiguityMixin:
known_wsp_da = dict()
known_wi_da = None
known_w_da = dict()
try:
from .. import raster

da = raster.testDataArray((1, 4, 4), missing_vals=False)
except ImportError:
da = None

def setup_method(self):
self.__dict__.update(
Expand Down Expand Up @@ -109,6 +117,8 @@ def test_from_geodataframe_order(self):
assert w.id_order[:5] == expected

def test_from_xarray(self):
pytest.importorskip("xarray")

w = self.cls.from_xarray(self.da, sparse=False, n_jobs=-1)
assert w[self.known_wi_da] == self.known_w_da
ws = self.cls.from_xarray(self.da)
Expand Down
6 changes: 3 additions & 3 deletions libpysal/weights/tests/test_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import numpy as np
import pandas as pd
import pytest
from xarray import DataArray

from .. import raster


class Testraster:
def setup_method(self):
pytest.importorskip("xarray")
self.da1 = raster.testDataArray()
self.da2 = raster.testDataArray((1, 4, 4), missing_vals=False)
self.da3 = self.da2.rename({"band": "layer", "x": "longitude", "y": "latitude"})
Expand Down Expand Up @@ -77,9 +76,10 @@ def test_da2_wsp(self):
assert w2.index.tolist() == self.da2.to_series().index.tolist()

def test_w2da(self):
xarray = pytest.importorskip("xarray")
w2 = raster.da2W(self.da2, "rook", n_jobs=-1)
da2 = raster.w2da(self.da2.data.flatten(), w2, self.da2.attrs, self.da2.coords)
da_compare = DataArray.equals(da2, self.da2)
da_compare = xarray.DataArray.equals(da2, self.da2)
assert da_compare == True

def test_wsp2da(self):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dependencies = [
"requests>=2.27",
"scipy>=1.8",
"shapely>=2.0.1",
"xarray>=2022.3",
]

[project.urls]
Expand All @@ -49,6 +48,7 @@ plus = [
"pyarrow>=7.0",
"scikit-learn>=1.1",
"sqlalchemy>=2.0",
"xarray>=2022.3",
"zstd",
]
dev = [
Expand Down