Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: bar mixed units, allow ValueError as well#13187

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dopplershift merged 3 commits intomatplotlib:masterfromjklymak:fix-pandas-datetime
Jan 21, 2019

Conversation

jklymak
Copy link
Member

PR Summary

Closes#13186

Follow up to#12903 where we try and do math first forbar (x+dx) before units conversion. Pandas throws aValueError for a previously working case. This adds that to the allowableexcepts...

PR Checklist

  • Has Pytest style unit tests
  • Code isFlake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak
Copy link
MemberAuthor

QT tests are failing - not this PR

NelleV
NelleV previously requested changesJan 16, 2019
Copy link
Member

@NelleVNelleV left a comment

Choose a reason for hiding this comment

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

Can you add a test that the error is not being raised when using pandas?

@jklymak
Copy link
MemberAuthor

100% agree that pandas datetimes + bar should be tested.

OTOH, I'm not 100% convinced its matplotlib that should be responsible for those tests if the pandas datetime unit converters are registered, which they are in this case. See#11664 for where I propose we explictlyunregister pandas datetime unit conversion so then we can test our own converters (which work with basic pandas objects without the need for their converters). This was prompted byimport pandas no longer registering their converters by default. They backed down on that change, but may re-impliment it at some point.

Not to say pandas' own converters shouldn't work - but it seems that they should be responsible for reporting breakages to us (like this one). However, I'm open to the idea we should fully test pandas if that is how it should be done.

For this particular case, I'm pretty ignorant about how the user got to the point wherebar worked at all (#13186), so I'm hesitant to add to the tests. But if someone knoweledgeable of pandas wanted to add or propose a test, I'm more than happy for that to go in...

@NelleV
Copy link
Member

Have we reported the breakage to pandas? If that is the case, we may want to simply add a test and a comment that this should be fixed in pandas version XXX, and remove the work around and and the test when times come.
Does that seem reasonable ?

@jklymak
Copy link
MemberAuthor

Hmm, looking at it again, I guess pandas thinks its a ValueError becauseself.freq is None.

In any case, not convinced this needs a test from our end, but the change should go in to make theexcept clause here as liberal as possible. In fact I'd argue its should be a bare except - if addingconvert(x+dx) fails for any reason give us the old behaviour of just callingconvert(dx)

@jklymak
Copy link
MemberAuthor

... ah apparentlyexcept Exception is the way to do this cleanly without a dangerous bare exception. Hopefully that is deemed OK by folks...

@@ -2057,7 +2057,7 @@ def _convert_dx(dx, x0, xconv, convert):
dx = [convert(x0 + ddx) - x for ddx in dx]
if delist:
dx = dx[0]
except(TypeError, AttributeError) as e:
exceptException:
Copy link
Contributor

Choose a reason for hiding this comment

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

please leave a comment justifying (briefly) the nonspecific catch-everything behavior.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't that catch everything?

Copy link
Contributor

Choose a reason for hiding this comment

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

In principle I'm ok withexcept Exception:, but fortargetted code. That's a pretty bigtry block to be catching withException--a lot of unexpected behavior could happen in those lines. Is it possible to just wrap the try arounddx = [convert(x0 + ddx) - x for ddx in dx]?

timhoffm reacted with thumbs up emoji
FIX: make exception in bar for convert(x+dx) more liberal
@NelleV
Copy link
Member

The current solution catches all exceptions, which we should avoid. It means will accidentally catch errors and exception we don't want to catch. I don't think the proposed solution is reasonable (sorry!)

@NelleV
Copy link
Member

(I need to run, but I'll review this more carefully in the next day or so)

@jklymak
Copy link
MemberAuthor

@NelleV I'm happy to go back to explicit exception types, butexcept Exceptions is the pep-8 way to make exception as liberal as possible:

A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to except BaseException:).

so I thought this would be OK.

https://www.python.org/dev/peps/pep-0008/

@NelleV
Copy link
Member

@jklymak But making catching exception as liberal as possible is not good practice. It means the code "works", in cases where it should probably fail. It actually happened to me several time with Matplotlib that the plot would show and be wrong due to broad error catching such as this one.

I'll dismiss my review, as I am about to board a plane and will be offline for the next 24h, but I think it is better to be as narrow and explicit as possible when catching errors.

@NelleVNelleV dismissed theirstale reviewJanuary 18, 2019 03:17

Not available in the near future to review this PR.

@jklymak
Copy link
MemberAuthor

Tightened exception

@dopplershift I can't make the try-except block shorter because the error is sometimes in the procedure that gets the first element.

Just to be clear - the idea is "try some stuff to get this to work. If that fails just do what we did before this PR". So having this try/except block makes things a bit better at no cost (other than code complexity).

OTOH I don't feel passionately about this solution. If someone has a better solution forbar that would be great.

@dopplershift
Copy link
Contributor

@jklymak That's fine--but then for a block that big, I agree with@NelleV that we should be as specific as possible in the exceptions caught. IMHOexcept Exception: is only ok when there's one specific line that you're catching errors from.

@jklymak
Copy link
MemberAuthor

@dopplershift sure, but is the new version OK? It has three explicit errors.

Copy link
Contributor

@dopplershiftdopplershift left a comment

Choose a reason for hiding this comment

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

@jklymak Sorry, new version is fine. Was holding off on review due to failing CI and lack of time to dig in.

@dopplershiftdopplershift merged commita9b4fd5 intomatplotlib:masterJan 21, 2019
@NelleV
Copy link
Member

That PR was missing a test. I'll create a PR to fix this.

@NelleVNelleV mentioned this pull requestJan 21, 2019
@dopplershift
Copy link
Contributor

Oops. Thanks.

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

@NelleVNelleVNelleV left review comments

@anntzeranntzeranntzer left review comments

@dopplershiftdopplershiftdopplershift approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.1.0
Development

Successfully merging this pull request may close these issues.

ax.bar throws when x axis is pandas datetime
6 participants
@jklymak@NelleV@dopplershift@anntzer@timhoffm@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp