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

New .broadcast_like() incorrect #3129

Closed
DavidMertz opened this issue Jul 14, 2019 · 2 comments · Fixed by #3130
Closed

New .broadcast_like() incorrect #3129

DavidMertz opened this issue Jul 14, 2019 · 2 comments · Fixed by #3130

Comments

@DavidMertz
Copy link
Contributor

Unfortunately, more robust tests show there is some logic problem in the @dcherian solution to #2885. I was merging my work in #3127 with his more-principled refactoring in #3086, and my tests showed an error in the refactoring.

@DavidMertz
Copy link
Contributor Author

In https://github.com/DavidMertz/xarray/tree/feature/2885-broadcast_like-merge-branch I have created a temporary method .broadcast_like_naive() and have created a test against the naive implementation that is identical to the test against the refactored code.

We actually get the failure in the call to .broadcast_like() itself, i.e. not in the assertion about the result:

___________________________________________ TestDataArray.test_broadcast_like ____________________________________________

self = <xarray.tests.test_dataarray.TestDataArray object at 0x7f2287e3a828>

    def test_broadcast_like(self):
        arr1 = DataArray(np.ones((2, 3)), dims=['x', 'y'],
                         coords={'x': ['a', 'b'], 'y': ['a', 'b', 'c']})
        arr2 = DataArray(np.ones((3, 2)), dims=['x', 'y'],
                         coords={'x': ['a', 'b', 'c'], 'y': ['a', 'b']})
        orig1, orig2 = broadcast(arr1, arr2)
>       new1 = arr2.broadcast_like(arr1)

xarray/tests/test_dataarray.py:1276: 
[...]
E                   ValueError: conflicting sizes for dimension 'y': length 2 on the data but length 3 on coordinate 'y'

@DavidMertz
Copy link
Contributor Author

DavidMertz commented Jul 14, 2019

With the following method instead, the identical test succeeds (modulo using the temporary method for tests, of course):

    def broadcast_like_naive(self,
                       other: Union['DataArray', Dataset],
                       exclude=None) -> 'DataArray':
        return broadcast(other, self)[1]

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 a pull request may close this issue.

1 participant