-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Fix Axes.hist crash for numpy timedelta64 inputs #31203
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
Changes from 1 commit
2275f59
bb8ed97
df468b2
5fa7cc0
4d257c6
6c45d7c
62d0716
ea2b96d
432f787
c07a991
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7416,7 +7416,16 @@ | |
|
|
||
| # Massage 'x' for processing. | ||
| x = cbook._reshape_2D(x, 'x') | ||
| nx = len(x) # number of datasets | ||
| nx = len(x) | ||
|
|
||
|
Check warning on line 7420 in lib/matplotlib/axes/_axes.py
|
||
| new_x = [] | ||
| for xi in x: | ||
| arr = np.asarray(xi) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary. So at least x = [arr / np.timedelta64(1, 'D') if np.issubdtype(arr.dtype, np.timedelta64) else arr
for arr in x]is possible. Another question to be investigated: Is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, which is the whole problem here. If it was possible to cast timedelta64 to float, the comparison would work.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if np.issubdtype(arr.dtype, np.timedelta64): | ||
| arr = arr / np.timedelta64(1, 'D') | ||
| new_x.append(arr) | ||
|
|
||
| x = new_x | ||
|
|
||
| # Process unit information. _process_unit_info sets the unit and | ||
| # converts the first dataset; then we convert each following dataset | ||
|
|
@@ -7470,16 +7479,14 @@ | |
| # does not do this for us when guessing the range (but will | ||
| # happily ignore nans when computing the histogram). | ||
| if bin_range is None: | ||
| xmin = np.inf | ||
| xmax = -np.inf | ||
| for xi in x: | ||
| if len(xi): | ||
| # python's min/max ignore nan, | ||
| # np.minnan returns nan for all nan input | ||
| xmin = min(xmin, np.nanmin(xi)) | ||
| xmax = max(xmax, np.nanmax(xi)) | ||
| if xmin <= xmax: # Only happens if we have seen a finite value. | ||
| bin_range = (xmin, xmax) | ||
| flat = [np.ravel(xi) for xi in x if len(xi)] | ||
| if flat: | ||
| all_data = np.concatenate(flat) | ||
| xmin = np.nanmin(all_data) | ||
| xmax = np.nanmax(all_data) | ||
| bin_range = (xmin, xmax) | ||
| else: | ||
| bin_range = None | ||
|
scottshambaugh marked this conversation as resolved.
Outdated
scottshambaugh marked this conversation as resolved.
Outdated
|
||
|
|
||
| # If bins are not specified either explicitly or via range, | ||
| # we need to figure out the range required for all datasets, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.