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

Revert "Do not attempt to broadcast when global option ``arithmetic_b… #8829

Closed
wants to merge 1 commit into from

Conversation

dcherian
Copy link
Contributor

…roadcast=False`` (#8784)"

This reverts commit 11f89ec.

Reverting #8784

Sadly that PR broke a lot of tests by breaking create_test_data with

from xarray.tests import create_test_data
create_test_data()
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[3], line 2
      1 from xarray.tests import create_test_data
----> 2 create_test_data()

File [~/repos/xarray/xarray/tests/__init__.py:329](http://localhost:8888/lab/workspaces/auto-P/tree/repos/devel/arraylake/~/repos/xarray/xarray/tests/__init__.py#line=328), in create_test_data(seed, add_attrs, dim_sizes)
    327 obj.coords["numbers"] = ("dim3", numbers_values)
    328 obj.encoding = {"foo": "bar"}
--> 329 assert all(var.values.flags.writeable for var in obj.variables.values())
    330 return obj

AssertionError:

Somehow that code changes whether IndexVariable.values returns a writeable numpy array. I spent some time debugging but couldn't figure it out.

cc @etienneschalk

@dcherian
Copy link
Contributor Author

Well this makes more sense. That PR didn't change behaviour. I must have a bad environment.

@dcherian dcherian closed this Mar 13, 2024
@keewis
Copy link
Collaborator

keewis commented Mar 13, 2024

a local bisect in a fresh environment confirms that it is the merge of #8784 that causes the failures, but I'm not sure why CI still fails even after the revert.

Edit: a local revert does fix it as well, let me try pushing that here to see if there was just something wrong with the environment? Otherwise could also be the caching of the environment that causes weird issues.

A minimal reproducer is just

python -c 'from xarray.tests import create_test_data; create_test_data()'

@keewis keewis reopened this Mar 13, 2024
@keewis
Copy link
Collaborator

keewis commented Mar 13, 2024

okay, wow. The issue appears to actually be the import of dask-expr (for the importorskip in xarray.tests), not the code of the PR.

@keewis
Copy link
Collaborator

keewis commented Mar 13, 2024

pinning dask-expr<1.0 appears to work, which also downgrades dask and distributed, so the issue might be there.

For a slightly smaller reproducer, try:

def example():
    obj = Dataset()
    obj["dim2"] = ("dim2", 0.5 * np.arange(9))
    obj["time"] = ("time", pd.date_range("2000-01-01", periods=20)
    print({k: v.data.flags for k, v in obj.variables.items()})
    return obj

example()
import dask_expr
example()

with dask_expr=1.0.1 we get the writable flag set to false after the import.

@dcherian
Copy link
Contributor Author

Crazy I had the same git bisect experience. Thought I was going crazy!

@keewis
Copy link
Collaborator

keewis commented Mar 13, 2024

I think I found it. dask-expr>=1.0 sets pd.set_option("mode.copy_on_write", True) on import, which causes the change in behavior. This reproduces as well (note how the writable flag changes from True to False after the call):

def example():
    obj = Dataset()
    obj["dim2"] = ("dim2", 0.5 * np.arange(9))
    obj["time"] = ("time", pd.date_range("2000-01-01", periods=20)
    print({k: v.data.flags for k, v in obj.variables.items()})
    return obj

example()
pd.set_options("mode.copy_on_write", True)
example()

which makes sense, because both are dimension coordinates and thus have a default pandas index.

@dcherian
Copy link
Contributor Author

yes, I suspected Pandas but downgrading didn't change anything

@dcherian dcherian closed this Mar 15, 2024
@dcherian dcherian deleted the revert-arith-broadcast branch March 20, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants