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

cftime plotting fails on upstream-dev #4265

Closed
dcherian opened this issue Jul 24, 2020 · 5 comments · Fixed by #4272
Closed

cftime plotting fails on upstream-dev #4265

dcherian opened this issue Jul 24, 2020 · 5 comments · Fixed by #4272

Comments

@dcherian
Copy link
Contributor

seen in https://dev.azure.com/xarray/xarray/_build/results?buildId=3365&view=logs&jobId=2280efed-fda1-53bd-9213-1fa8ec9b4fa8&j=2280efed-fda1-53bd-9213-1fa8ec9b4fa8&t=175181ee-1928-5a6b-f537-168f7a8b7c2d

=========================== short test summary info ============================
FAILED xarray/tests/test_plot.py::TestCFDatetimePlot::test_cfdatetime_line_plot
FAILED xarray/tests/test_plot.py::TestCFDatetimePlot::test_cfdatetime_pcolormesh_plot
FAILED xarray/tests/test_plot.py::TestCFDatetimePlot::test_cfdatetime_contour_plot

e.g.

=================================== FAILURES ===================================
_________________ TestCFDatetimePlot.test_cfdatetime_line_plot _________________

self = <xarray.tests.test_plot.TestCFDatetimePlot object at 0x7f71d66219d0>

    def test_cfdatetime_line_plot(self):
E       ValueError: setting an array element with a sequence. The requested array would exceed the maximum number of dimension of 1.

/usr/share/miniconda/envs/xarray-tests/lib/python3.8/site-packages/matplotlib/transforms.py:943: ValueError
@spencerkclark
Copy link
Member

spencerkclark commented Jul 25, 2020

Thanks for noting this @dcherian; it seems like there may have been a change in NumPy that caused this. E.g. with NumPy master this doesn't work:

>>> import numpy as np
>>> np.__version__
'1.20.0.dev0+2d12d0c'
>>> a = np.array([[1., 2.], [3., 4.]])
>>> a[:, 0] = (np.array([0.]), np.array([3650.]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: setting an array element with a sequence. The requested array would exceed the maximum number of dimension of 1.

But with earlier versions of NumPy it does:

>>> import numpy as np
>>> np.__version__
'1.19.1'
>>> a = np.array([[1., 2.], [3., 4.]])
>>> a[:, 0] = (np.array([0.]), np.array([3650.]))
>>> a
array([[0.00e+00, 2.00e+00],
       [3.65e+03, 4.00e+00]])

I'll need to investigate more to see whether this is something to bring up in the matplotlib or NumPy issue tracker (it could be nc-time-axis related too). I'm not sure if there's anything we can do in xarray to fix this. It's probably best to xfail these tests for the time being.

@max-sixty
Copy link
Collaborator

xfailed with: #4271

@spencerkclark
Copy link
Member

I think this NumPy issue is related: numpy/numpy#16939. numpy/numpy#16943 was merged yesterday, which appears to have at least allowed this to continue to work for the time being:

>>> import numpy as np
>>> a = np.array([[1., 2.], [3., 4.]])
>>> a[:, 0] = (np.array([0.]), np.array([3650.]))
<stdin>:1: DeprecationWarning: setting an array element with a sequence. This was supported in some cases where the elements are arrays with a single element. For example `np.array([1, np.array([2])], dtype=int)`. In the future this will raise the same ValueError as `np.array([1, [2]], dtype=int)`.

Given that this will be deprecated, I think it's still worthwhile to investigate what's causing this upstream in matplotlib or nc-time-axis, but it should be safe to un-xfail these tests again.

@spencerkclark
Copy link
Member

I think I tracked down the root of this odd behavior in nc-time-axis; see SciTools/nc-time-axis#45 for more details.

@dcherian
Copy link
Contributor Author

nice work spencer!

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

Successfully merging a pull request may close this issue.

3 participants