Skip to content

BUG: fix the error msg of empty hstack input - #8801

Merged
charris merged 1 commit into
numpy:masterfrom
zixu-zhao:fix/hstack-error-msg
Mar 25, 2017
Merged

charris merged 1 commit into
numpy:masterfrom
zixu-zhao:fix/hstack-error-msg

Conversation

@zixu-zhao

Copy link
Copy Markdown

Raise the meaningful error msg for np.hstack() under empty input.

Closes #8790

Comment thread numpy/core/shape_base.py Outdated

@eric-wieser eric-wieser Mar 20, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An alternative fix would be to simply change this line to arrs and arrs[0].ndim == 1, which would then allow concatenate to produce an appropriate error message

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, that's really helpful!

Comment thread numpy/core/shape_base.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The other error message uses array not element.

Comment thread numpy/core/shape_base.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if not arrs would be more pythonic IMO

@zixu-zhao
zixu-zhao force-pushed the fix/hstack-error-msg branch from 68603f1 to 7523ac5 Compare March 20, 2017 21:51
@zixu-zhao

zixu-zhao commented Mar 20, 2017 •

Copy link
Copy Markdown
Author

@eric-wieser I have updated the implementation and squashed the previous commit. Thanks for the help!

@MSeifert04

MSeifert04 commented Mar 20, 2017 •

Copy link
Copy Markdown
Contributor

I'm not actually opposed but this will break backwards-compatibility. Code that checked for IndexError before needs to check for ValueError now. Not sure if anyone ever used this in a try: ... except IndexError: ... but these will get a nasty surprise.

Maybe safer to go with some sort of FutureWarning first or is it too unlikely?

In any case, shouldn't the change be tested?

@eric-wieser

eric-wieser commented Mar 20, 2017 •

Copy link
Copy Markdown
Member

@MSeifert04: I agree, changing the exception API is perhaps risky. But a futurewarning wouldn't help because:

  • People couldn't change their code to catch ValueError until the release where things are changed in numpy, so there's no way to prepare
    • To fix this, we could raise class FutureValueButCurrentlyIndexError(IndexError, ValueError): pass
  • Even then, we provide no way for the user to squash the warning, so they have no incentive to try and fix it

From a somewhat mean and not terribly valid point of view, if someone is relying on this behaviour and did not think to report the (relatively obvious) bug here, then perhaps they deserve the breakage?

At any rate, hstack can throw ValueError already for a different set of reasons, so the type of code with a try catch is likely to catch both


Yes, this needs tests. And if they're not there already, vstack and concatenate should test for this too.

@eric-wieser

Copy link
Copy Markdown
Member

Also, there's a typo in the commit message

@zixu-zhao
zixu-zhao force-pushed the fix/hstack-error-msg branch from 7523ac5 to d5bbd85 Compare March 20, 2017 22:07
@zixu-zhao

Copy link
Copy Markdown
Author

@eric-wieser Fix the typo.Sorry about that.

@eric-wieser

Copy link
Copy Markdown
Member

I would have saved that fixup till you add the tests, but whatever

@zixu-zhao zixu-zhao changed the title BUG: fix the error msg of empty hastack input BUG: fix the error msg of empty hstack input Mar 20, 2017
@zixu-zhao
zixu-zhao force-pushed the fix/hstack-error-msg branch from d5bbd85 to 9d225b9 Compare March 20, 2017 23:03
@zixu-zhao

Copy link
Copy Markdown
Author

@eric-wieser Hi, I added the test. I haven't done testing addition before, so please let me know if I did something wrong. Thanks!

@eric-wieser

eric-wieser commented Mar 20, 2017 •

Copy link
Copy Markdown
Member

Test looks good - but let's add one for vstack as well, since that also doesn't test this. No need to mention the test in the commit message - it's usually implied.

Comment thread numpy/core/tests/test_shape_base.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit-pick: the test for concatenate uses () not []

@zixu-zhao
zixu-zhao force-pushed the fix/hstack-error-msg branch from 9d225b9 to 235ce08 Compare March 20, 2017 23:51
@zixu-zhao

Copy link
Copy Markdown
Author

Updated the commit msg and tests.

@eric-wieser

Copy link
Copy Markdown
Member

Looks good to me. Regarding @MSeifert04's comment, at the very least there should be something in the compatibility section of the 1.13 release notes

@zixu-zhao
zixu-zhao force-pushed the fix/hstack-error-msg branch from 235ce08 to b1bc302 Compare March 21, 2017 00:12
@zixu-zhao

Copy link
Copy Markdown
Author

Updated the 1.13 release notes.

@eric-wieser eric-wieser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally looks good to me, but someone else should probably weigh in on @MSeifert04's point

Comment thread doc/release/1.13.0-notes.rst Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Bit unusual to have a heading with no content here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I will change it. I didn't realize that is a heading line. I just thought that was a dividing line.

@zixu-zhao
zixu-zhao force-pushed the fix/hstack-error-msg branch from b1bc302 to 1273caf Compare March 21, 2017 22:13
@zixu-zhao

Copy link
Copy Markdown
Author

Updated the header and content of 1.13 release notes.

===================


Error type changes

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You've reminded me that I should add another entry under this heading regarding #8584, so thanks for that

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

My pleasure :)

@charris

charris commented Mar 25, 2017

Copy link
Copy Markdown
Member

In theory, we probably shouldn't be changing error types, in practice it isn't uncomon and doesn't seem to cause problems. I don't really see how we can avoid it if we refactor python code as things are likely to fail in different places. i suppose we could do all checks up front but we generally rely on ducktyping failing one place or another. The errors are rarely part of the documentation...

@charris

charris commented Mar 25, 2017

Copy link
Copy Markdown
Member

Thanks @ZZhaoTireless .

@zixu-zhao

Copy link
Copy Markdown
Author

Thanks for reviewing and merging my code :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants