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

getting a "truth value of an array" error when supplying my own concat_dim. #2647

Closed
WeatherGod opened this issue Jan 4, 2019 · 7 comments
Closed
Labels

Comments

@WeatherGod
Copy link
Contributor

This bug was introduced sometime after v0.11.0 and has turned up in my test suite using v0.11.2. I'll pass a DataArray() as my concat_dim, and the failure will happen at line 609 in backends/api.py because of: if concat_dim is None or concat_dim == _CONCAT_DIM_DEFAULT:

I am not sure how this change got through. In #2048, I added a unit test that passes a DataArray as a concat_dim argument.

@shoyer shoyer added the bug label Jan 4, 2019
@WeatherGod
Copy link
Contributor Author

To be more explicit, the issue is that concat_dim == _CONCAT_DIM_DEFAULT is ill-advised because the type of concat_dim is not guaranteed to be a scalar. In fact, the elif of that area of code in api.py explicitly tests if concat_dim is or is not a list.

@shoyer
Copy link
Member

shoyer commented Jan 4, 2019

Indeed, this is should definitely be concat_dim is _CONCAT_DIM_DEFAULT for comparing to a sentinel value.

I think this snuck through because NumPy will automatically cast size 1 arrays (of any shape) to booleans :(. We should probably adapt that test to include an explicit dimension of size greater than 1.

@WeatherGod
Copy link
Contributor Author

ah! that's why it snuck through! I have been raking my brain on this for the past hour! shall I go ahead and make a PR?

@WeatherGod
Copy link
Contributor Author

actually, we could simplify the conditional to be just concat_dim is _CONCAT_DIM_DEFAULT and not bother with the None test.

@shoyer
Copy link
Member

shoyer commented Jan 4, 2019

I think concat_dim=None may mean something special here, which is why we have _CONCAT_DIM_DEFAULT

@WeatherGod
Copy link
Contributor Author

scratch that... the test was an or, not a and.

WeatherGod added a commit to WeatherGod/xray that referenced this issue Jan 4, 2019
shoyer pushed a commit that referenced this issue Jan 5, 2019
…#2648)

* Change an `==` to an `is`. Fix tests so that this won't happen again.

Closes #2647 and re-affirms #1988.

* Reuse the same _CONCAT_DIM_DEFAULT object
@TomNicholas
Copy link
Member

I just wanted to clarify that concat_dim=None very much does mean something special, it means "don't use concat on these datasets at all, just use merge". This is documented under the concat_dim argument description of the docs for auto_combine here.

Also @WeatherGod I think this bug was introduced by me in #2553, but should be checked again once #2616 is finished, because the API will change.

shoyer pushed a commit that referenced this issue Jan 24, 2019
…#2648)

* Change an `==` to an `is`. Fix tests so that this won't happen again.

Closes #2647 and re-affirms #1988.

* Reuse the same _CONCAT_DIM_DEFAULT object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants