Skip to content

Fix CI test failures #393

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

Merged
merged 5 commits into from
Mar 22, 2025
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: 0 additions & 2 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ jobs:
- name: Setup Conda Environment
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
use-mamba: true
python-version: ${{ matrix.python-version }}
environment-file: continuous_integration/environment-${{ matrix.python-version }}.yml
activate-environment: dask-image-testenv
Expand Down
7 changes: 4 additions & 3 deletions dask_image/ndinterp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,11 @@ def rotate(
if reshape:
# Compute transformed input bounds
iy, ix = in_plane_shape
out_bounds = rot_matrix @ [[0, 0, iy, iy],
[0, ix, 0, ix]]
in_bounds = np.array([[0, 0, iy, iy],
[0, ix, 0, ix]])
out_bounds = rot_matrix @ in_bounds
# Compute the shape of the transformed input plane
out_plane_shape = (out_bounds.ptp(axis=1) + 0.5).astype(int)
out_plane_shape = (np.ptp(out_bounds, axis=1) + 0.5).astype(int)
else:
out_plane_shape = img_shape[axes]

Expand Down
5 changes: 4 additions & 1 deletion dask_image/ndmeasure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import operator
import warnings
from dask import compute, delayed
import dask.config as dask_config

import dask.array as da
import dask.bag as db
Expand Down Expand Up @@ -244,7 +245,9 @@ def find_objects(label_image):
result = bag.fold(functools.partial(_find_objects, label_image.ndim), split_every=2).to_delayed()
meta = dd.utils.make_meta([(i, object) for i in range(label_image.ndim)])
result = delayed(compute)(result)[0] # avoid the user having to call compute twice on result
result = dd.from_delayed(result, meta=meta, prefix="find-objects-", verify_meta=False)

with dask_config.set({'dataframe.convert-string': False}):
result = dd.from_delayed(result, meta=meta, prefix="find-objects-", verify_meta=False)

return result

Expand Down
7 changes: 5 additions & 2 deletions dask_image/ndmeasure/_utils/_find_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pandas as pd
from dask.delayed import Delayed
import dask.dataframe as dd
import dask.config as dask_config


def _array_chunk_location(block_id, chunks):
Expand Down Expand Up @@ -67,9 +68,11 @@ def _find_objects(ndim, df1, df2):
"""Main utility function for find_objects."""
meta = dd.utils.make_meta([(i, object) for i in range(ndim)])
if isinstance(df1, Delayed):
df1 = dd.from_delayed(df1, meta=meta)
with dask_config.set({'dataframe.convert-string': False}):
df1 = dd.from_delayed(df1, meta=meta)
if isinstance(df2, Delayed):
df2 = dd.from_delayed(df2, meta=meta)
with dask_config.set({'dataframe.convert-string': False}):
df2 = dd.from_delayed(df2, meta=meta)
Comment on lines 70 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough given compute happens later?

Do we have a way to test this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough given compute happens later?

Yes, consider this code snippet:

import dask.dataframe as dd
import dask.array as da
from dask import delayed
import pandas as pd
import dask.config as dask_config

x = dd.from_delayed(delayed(pd.Series([slice(2)])))

with dask_config.set({'dataframe.convert-string': False}):
    x_cm = dd.from_delayed(delayed(pd.Series([slice(2)])))

print('x', x)
print('x_cm', x_cm)

print('x computed', x.compute())
print('x_cm computed', x_cm.compute())

outputs

x Dask Series Structure:
npartitions=1
    string
       ...
Dask Name: to_string_dtype, 3 expressions
Expr=ArrowStringConversion(frame=FromDelayed(5621810))
x_cm Dask Series Structure:
npartitions=1
    object
       ...
Dask Name: fromdelayed, 2 expressions
Expr=FromDelayed(79a507f)
x computed 0    slice(None, 2, None)
dtype: string
x_cm computed 0    slice(None, 2, None)
dtype: object

Also he tests do perform a compute and fail without the context manager in place, so it should be covered:

computed_result = result.compute()
assert isinstance(computed_result, pd.DataFrame)
expected = pd.DataFrame.from_dict(
{0: {111: slice(1, 3), 222: slice(3, 4), 333: slice(0, 2)},
1: {111: slice(0, 2), 222: slice(3, 8), 333: slice(7, 10)}}
)
assert computed_result.equals(expected)

ddf = dd.merge(df1, df2, how="outer", left_index=True, right_index=True)
result = ddf.apply(_merge_bounding_boxes, ndim=ndim, axis=1, meta=meta)
return result
3 changes: 2 additions & 1 deletion tests/test_dask_image/test_imread/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def test_tiff_imread(tmpdir, seed, nframes, shape, dtype, is_pathlib_Path): # n
fn = str(dirpth.join("test.tiff"))
with tifffile.TiffWriter(fn) as fh:
for i in range(len(a)):
fh.save(a[i], contiguous=True)
fh.write(a[i], contiguous=True)

if is_pathlib_Path:
fn = pathlib.Path(fn)
d = dask_image.imread.imread(fn, nframes=nframes)
Expand Down
Loading