Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
hekaisheng committed Feb 8, 2022
1 parent 8ea4426 commit 001394d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
12 changes: 5 additions & 7 deletions mars/dataframe/sort/sort_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def _tile_series(cls, op):

@classmethod
def _tile(cls, op):
if op.inputs[0].ndim == 2:
inp = op.inputs[0]
if inp.shape[op.axis] == 0:
# if the length is zero, return input directly
return inp
if inp.ndim == 2:
return (yield from cls._tile_dataframe(op))
else:
return (yield from cls._tile_series(op))
Expand Down Expand Up @@ -245,9 +249,6 @@ def dataframe_sort_values(
axis = validate_axis(axis, df)
if axis != 0:
raise NotImplementedError("Only support sort on axis 0")
if df.shape[axis] == 0:
# if the length is zero, return input directly
return df
psrs_kinds = _validate_sort_psrs_kinds(psrs_kinds)
by = by if isinstance(by, (list, tuple)) else [by]
op = DataFrameSortValues(
Expand Down Expand Up @@ -362,9 +363,6 @@ def series_sort_values(
axis = validate_axis(axis, series)
if axis != 0:
raise NotImplementedError("Only support sort on axis 0")
if series.shape[axis] == 0:
# if the length is zero, return input directly
return series
psrs_kinds = _validate_sort_psrs_kinds(psrs_kinds)
op = DataFrameSortValues(
axis=axis,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_pairwise_distances_execution(setup):
weight = np.random.rand(5)
d = pairwise_distances(x, y, metric="wminkowski", p=3, w=weight)
result = d.execute().fetch()
expected = sk_pairwise_distances(raw_x, raw_y, metric="wminkowski", p=3, w=weight)
expected = sk_pairwise_distances(raw_x, raw_y, metric="minkowski", p=3, w=weight)
np.testing.assert_almost_equal(result, expected)

# test pdist
Expand Down
11 changes: 10 additions & 1 deletion mars/tensor/datasource/from_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ def execute(cls, ctx, op):
def fromzarr(path, group=None, dataset=None, chunk_size=None):
import zarr

try:
# since v2.11.0, zarr convert mutable mappings to KVStore
from zarr.storage import KVStore as zarr_kvstore
except ImportError:
zarr_kvstore = None

if isinstance(path, zarr.Array):
arr = path
if isinstance(arr.store, FSMap):
if zarr_kvstore is None and isinstance(arr.store, FSMap):
root = arr.store.root
path, dataset = root.rsplit("/", 1)
elif zarr_kvstore and isinstance(arr.store, zarr_kvstore):
root = arr.store._mutable_mapping.root
path, dataset = root.rsplit("/", 1)
else:
path = arr.store.path
if "/" in arr.path and group is None:
Expand Down
2 changes: 1 addition & 1 deletion mars/tensor/random/tests/test_random_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_sparse_randint_execution(setup):
assert res.shape == (30, 50)
np.testing.assert_array_less(res.data, 2)
np.testing.assert_array_less(0, res.data)
assert pytest.approx((res >= 1).toarray().sum(), 30 * 50 * 0.1, abs=20)
assert (res >= 1).toarray().sum() == pytest.approx(30 * 50 * 0.1, abs=20)


random_test_options = namedtuple("random_test_options", ["func_name", "args", "kwargs"])
Expand Down
5 changes: 5 additions & 0 deletions mars/tensor/spatial/distance/cdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ def cdist(XA, XB, metric="euclidean", **kwargs):
"3rd argument metric must be a string identifier " "or a function."
)

# scipy remove "wminkowski" since v1.8.0, use "minkowski" with `w=`
# keyword-argument for the given weight.
if metric == "wminkowski":
metric = "minkowski"

p = kwargs.pop("p", None)
w = kwargs.pop("w", None)
if w is not None:
Expand Down
5 changes: 5 additions & 0 deletions mars/tensor/spatial/distance/pdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ def pdist(X, metric="euclidean", **kwargs):
"2nd argument metric must be a string identifier " "or a function."
)

# scipy remove "wminkowski" since v1.8.0, use "minkowski" with `w=`
# keyword-argument for the given weight.
if metric == "wminkowski":
metric = "minkowski"

p = kwargs.pop("p", None)
w = kwargs.pop("w", None)
if w is not None:
Expand Down
4 changes: 2 additions & 2 deletions mars/tensor/spatial/distance/tests/test_distance_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_pdist_execution(setup):
w = tensor(weight, chunk_size=7)
dist = distance.pdist(x, metric="wminkowski", p=3, w=w)
result = dist.execute().fetch()
expected = sp_pdist(raw, metric="wminkowski", p=3, w=weight)
expected = sp_pdist(raw, metric="minkowski", p=3, w=weight)
np.testing.assert_array_equal(result, expected)

# test V
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_cdist_execution(setup):
w = tensor(weight, chunk_size=7)
dist = distance.cdist(xa, xb, metric="wminkowski", p=3, w=w)
result = dist.execute().fetch()
expected = sp_cdist(raw_a, raw_b, metric="wminkowski", p=3, w=weight)
expected = sp_cdist(raw_a, raw_b, metric="minkowski", p=3, w=weight)
np.testing.assert_array_equal(result, expected)

# test V
Expand Down

0 comments on commit 001394d

Please sign in to comment.