home / github

Menu
  • GraphQL API
  • Search all tables

issues

Table actions
  • GraphQL API for issues

3 rows where user = 9513634 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date), closed_at (date)

type 2

  • pull 2
  • issue 1

state 2

  • closed 2
  • open 1

repo 1

  • xarray 3
id node_id number title user state locked assignee milestone comments created_at updated_at ▲ closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1437481995 I_kwDOAMm_X85VrjwL 7259 🐛 NetCDF4 RuntimeWarning if xarray is imported before netCDF4 s-weigand 9513634 open 0     18 2022-11-06T17:38:35Z 2024-04-28T20:11:35Z   CONTRIBUTOR      

What happened?

Yesterday we got a dependabot update PR to upgrade xarray from 2022.10.0 to 2022.11.0 and a test where we check for our own deprecation warnings failed because there was an additional unexpected warning. After some debugging we found that the warning was caused by calling xarray.Dataset.to_netcdf for the first time in our test suite, but did not trigger when calling it again.

After a lot of head-scratching and confusion, we found that it is an import order problem that can be solved by importing netCDF4 before importing xarray (we didn't import netCDF4 at all in our code).

What did you expect to happen?

No RuntimeWarning from netCDF4

Minimal Complete Verifiable Example

Python import xarray import warnings warnings.filterwarnings('error') import netCDF4

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

Python Traceback (most recent call last): File "d:\git\pyglotaran\glotaran\builtin\io\folder\test\test_folder_plugin.py", line 86, in <module> save_result(result_path="foo", format_name="folder", result=result) File "D:\git\pyglotaran\glotaran\plugin_system\io_plugin_utils.py", line 87, in wrapper return func(*args, **kwargs) File "D:\git\pyglotaran\glotaran\plugin_system\project_io_registration.py", line 473, in save_result paths = io.save_result( # type: ignore[call-arg] File "D:\git\pyglotaran\glotaran\builtin\io\folder\folder_plugin.py", line 192, in save_result save_dataset( File "D:\git\pyglotaran\glotaran\plugin_system\io_plugin_utils.py", line 87, in wrapper return func(*args, **kwargs) File "D:\git\pyglotaran\glotaran\plugin_system\data_io_registration.py", line 242, in save_dataset io.save_dataset( # type: ignore[call-arg] File "D:\git\pyglotaran\glotaran\builtin\io\netCDF\netCDF.py", line 24, in save_dataset data_to_save.to_netcdf(file_name, mode="w") File "C:\Anaconda3\envs\pyglotaran310\lib\site-packages\xarray\core\dataset.py", line 1903, in to_netcdf return to_netcdf( # type: ignore # mypy cannot resolve the overloads:( File "C:\Anaconda3\envs\pyglotaran310\lib\site-packages\xarray\backends\api.py", line 1176, in to_netcdf engine = _get_default_engine(path_or_file) File "C:\Anaconda3\envs\pyglotaran310\lib\site-packages\xarray\backends\api.py", line 140, in _get_default_engine return _get_default_engine_netcdf() File "C:\Anaconda3\envs\pyglotaran310\lib\site-packages\xarray\backends\api.py", line 118, in _get_default_engine_netcdf import netCDF4 # noqa: F401 File "C:\Anaconda3\envs\pyglotaran310\lib\site-packages\netCDF4\__init__.py", line 3, in <module> from ._netCDF4 import * File "src\netCDF4\_netCDF4.pyx", line 1, in init netCDF4._netCDF4 RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 16 from C header, got 96 from PyObject

Anything else we need to know?

The problem can be reproduced by running console python -c "import xarray;import warnings;warnings.filterwarnings('error');import netCDF4"

which throws the error python Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Anaconda3\envs\xarray\lib\site-packages\netCDF4\__init__.py", line 3, in <module> from ._netCDF4 import * File "src\netCDF4\_netCDF4.pyx", line 1, in init netCDF4._netCDF4 RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 16 from C header, got 96 from PyObject

When importing netCDF4 first all runs as expected console python -c "import netCDF4;import xarray;import warnings;warnings.filterwarnings('error');import netCDF4"

A git bisect shows that the first commit with this problem was https://github.com/pydata/xarray/commit/f32d354e295c05fb5c5ece7862f77f19d82d5894

```console $ git bisect start status: waiting for both good and bad commits (xarray) /d/git/xarray (main|BISECTING) $ git bisect good v2022.10.0 status: waiting for bad commit, 1 good commit known (xarray) /d/git/xarray (main|BISECTING) $ git bisect bad v2022.11.0 Bisecting: 23 revisions left to test after this (roughly 5 steps) [4944b9eb1483c1fbd0e86fd12f3fb894b325fb8d] Fix binning when labels are provided. (#7205) (xarray) /d/git/xarray ((4944b9eb...)|BISECTING) $ git bisect run python -c "import xarray;import warnings;warnings.filterwarnings('error');import netCDF4" running 'python' '-c' 'import xarray;import warnings;warnings.filterwarnings('\''error'\'');import netCDF4' Bisecting: 11 revisions left to test after this (roughly 4 steps) [f32d354e295c05fb5c5ece7862f77f19d82d5894] Lazy Imports (#7179) running 'python' '-c' 'import xarray;import warnings;warnings.filterwarnings('\''error'\'');import netCDF4' Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Anaconda3\envs\xarray\lib\site-packages\netCDF4\__init__.py", line 3, in <module> from ._netCDF4 import * File "src\netCDF4\_netCDF4.pyx", line 1, in init netCDF4._netCDF4 RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 16 from C header, got 96 from PyObject Bisecting: 5 revisions left to test after this (roughly 3 steps) [b9aedd0155548ed0f34506ecc255b1688f07ffaa] set_coords docs: see also Dataset.assign_coords (#7230) running 'python' '-c' 'import xarray;import warnings;warnings.filterwarnings('\''error'\'');import netCDF4' Bisecting: 2 revisions left to test after this (roughly 2 steps) [65bfa4d10a529f00a9f9b145d1cea402bdae83d0] Actually make the fast code path return early for Aligner.align (#7222) running 'python' '-c' 'import xarray;import warnings;warnings.filterwarnings('\''error'\'');import netCDF4' Bisecting: 0 revisions left to test after this (roughly 1 step) [fc9026b59d38146a21769cc2d3026a12d58af059] Avoid loading any data for reprs (#7203) running 'python' '-c' 'import xarray;import warnings;warnings.filterwarnings('\''error'\'');import netCDF4' f32d354e295c05fb5c5ece7862f77f19d82d5894 is the first bad commit commit f32d354e295c05fb5c5ece7862f77f19d82d5894 Author: Mick <mick.niklas@gmail.com> Date: Fri Oct 28 18:25:39 2022 +0200 Lazy Imports (#7179) * fix typing of BackendEntrypoint * make backends lazy * make matplotlib lazy and add tests for lazy modules * make flox lazy * fix generated docs on windows... * try fixing test * make pycompat lazy * make dask.array lazy * add import xarray without numpy or pandas benchmark * improve error reporting in test * fix import benchmark * add lazy import to whats-new * fix lazy import test * fix typos * fix windows stuff again asv_bench/benchmarks/import.py | 12 +- doc/whats-new.rst | 2 + xarray/backends/cfgrib_.py | 27 ++-- xarray/backends/common.py | 15 ++- xarray/backends/h5netcdf_.py | 19 ++- xarray/backends/netCDF4_.py | 16 +-- xarray/backends/pseudonetcdf_.py | 13 +- xarray/backends/pydap_.py | 24 ++-- xarray/backends/pynio_.py | 13 +- xarray/backends/scipy_.py | 12 +- xarray/backends/zarr.py | 15 +-- xarray/convert.py | 3 +- xarray/core/_aggregations.py | 247 ++++++++++++++++++++++++++++------- xarray/core/dataset.py | 3 +- xarray/core/duck_array_ops.py | 31 +++-- xarray/core/formatting.py | 36 ++--- xarray/core/indexing.py | 6 +- xarray/core/missing.py | 4 +- xarray/core/parallel.py | 20 +-- xarray/core/pycompat.py | 20 ++- xarray/core/utils.py | 19 +++ xarray/core/variable.py | 15 +-- xarray/plot/utils.py | 9 +- xarray/tests/test_backends.py | 4 +- xarray/tests/test_computation.py | 4 +- xarray/tests/test_dask.py | 3 +- xarray/tests/test_dataset.py | 4 +- xarray/tests/test_duck_array_ops.py | 4 +- xarray/tests/test_missing.py | 4 +- xarray/tests/test_plugins.py | 61 ++++++++- xarray/tests/test_sparse.py | 4 +- xarray/tests/test_variable.py | 4 +- xarray/util/generate_aggregations.py | 13 +- 33 files changed, 445 insertions(+), 241 deletions(-) bisect found first bad commit ```

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.6 | packaged by conda-forge | (main, Oct 7 2022, 20:14:50) [MSC v.1916 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: AMD64 Family 23 Model 8 Stepping 2, AuthenticAMD byteorder: little LC_ALL: None LANG: de_DE.UTF-8 LOCALE: ('de_DE', 'cp1252') libhdf5: 1.12.1 libnetcdf: 4.8.1 xarray: 2022.11.0 pandas: 1.5.1 numpy: 1.23.4 scipy: 1.9.3 netCDF4: 1.6.1 pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: 3.6.1 cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 59.8.0 pip: 22.2.2 conda: None pytest: 7.1.3 IPython: 8.5.0 sphinx: 5.2.3 None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7259/reactions",
    "total_count": 12,
    "+1": 8,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 4
}
    xarray 13221727 issue
1118113789 PR_kwDOAMm_X84xxbjr 6207 Fix missing dependecy definition of 'packaging' s-weigand 9513634 closed 0     19 2022-01-29T08:19:09Z 2022-02-01T18:29:04Z 2022-01-31T23:51:59Z CONTRIBUTOR   0 pydata/xarray/pulls/6207

Hi there, we just wanted to upgrade xarray to version 0.21.0 and our ASV workflow on the CI started failing.

python File "/home/runner/work/pyglotaran/pyglotaran/benchmark/.asv/env/76391772e92136ec87b9940d70226329/lib/python3.8/site-packages/xarray/core/dask_array_compat.py", line 4, in <module> from packaging.version import Version ModuleNotFoundError: No module named 'packaging' The reason is that packaging isn't a direct dependency of xarray.

```console $ johnnydep xarray 2022-01-29 08:28:38 [info ] init johnnydist [johnnydep.lib] dist=xarray parent=None 2022-01-29 08:28:40 [info ] init johnnydist [johnnydep.lib] dist=numpy>=1.18 parent=xarray 2022-01-29 08:28:44 [info ] init johnnydist [johnnydep.lib] dist=pandas>=1.1 parent=xarray 2022-01-29 08:28:47 [info ] init johnnydist [johnnydep.lib] dist=numpy>=1.18.5 parent=pandas>=1.1 2022-01-29 08:28:51 [info ] init johnnydist [johnnydep.lib] dist=python-dateutil>=2.8.1 parent=pandas>=1.1 2022-01-29 08:28:53 [info ] init johnnydist [johnnydep.lib] dist=pytz>=2020.1 parent=pandas>=1.1 2022-01-29 08:28:56 [info ] init johnnydist [johnnydep.lib] dist=six>=1.5 parent=python-dateutil>=2.8.1 name summary


xarray N-D labeled arrays and datasets in Python ├── numpy>=1.18 NumPy is the fundamental package for array computing with Python. └── pandas>=1.1 Powerful data structures for data analysis, time series, and statistics ├── numpy>=1.18.5 NumPy is the fundamental package for array computing with Python. ├── python-dateutil>=2.8.1 Extensions to the standard Python datetime module │ └── six>=1.5 Python 2 and 3 compatibility utilities └── pytz>=2020.1 World timezone definitions, modern and historical ```

The problem why your tests didn't catch this is that packaging is a dependency of pytest itself. ```console $ johnnydep pytest 2022-01-29 08:25:03 [info ] init johnnydist [johnnydep.lib] dist=pytest parent=None 2022-01-29 08:25:07 [info ] init johnnydist [johnnydep.lib] dist=atomicwrites>=1.0 parent=pytest 2022-01-29 08:25:09 [info ] init johnnydist [johnnydep.lib] dist=attrs>=19.2.0 parent=pytest 2022-01-29 08:25:11 [info ] init johnnydist [johnnydep.lib] dist=colorama parent=pytest 2022-01-29 08:25:14 [info ] init johnnydist [johnnydep.lib] dist=iniconfig parent=pytest 2022-01-29 08:25:16 [info ] init johnnydist [johnnydep.lib] dist=packaging parent=pytest 2022-01-29 08:25:18 [info ] init johnnydist [johnnydep.lib] dist=pluggy<2.0,>=0.12 parent=pytest 2022-01-29 08:25:20 [info ] init johnnydist [johnnydep.lib] dist=py>=1.8.2 parent=pytest 2022-01-29 08:25:23 [info ] init johnnydist [johnnydep.lib] dist=toml parent=pytest 2022-01-29 08:25:25 [info ] init johnnydist [johnnydep.lib] dist=pyparsing!=3.0.5,>=2.0.2 parent=packaging name summary


pytest pytest: simple powerful testing with Python ├── atomicwrites>=1.0 Atomic file writes. ├── attrs>=19.2.0 Classes Without Boilerplate ├── colorama Cross-platform colored terminal text. ├── iniconfig iniconfig: brain-dead simple config-ini parsing ├── packaging Core utilities for Python packages │ └── pyparsing!=3.0.5,>=2.0.2 Python parsing module ├── pluggy<2.0,>=0.12 plugin and hook calling mechanisms for python ├── py>=1.8.2 library with cross-python path, ini-parsing, io, code, log facilities └── toml Python Library for Tom's Obvious, Minimal Language ```

We also only saw our ASV workflow fail since ASV only installs the package and all direct runtime dependencies in the venv it runs the benchmark with.

I prepared a dummy PR on my fork to demonstrate that this fixes the issue.

Since the release is only 10h old maybe just do a quick post-release so most users won't even notice.

  • [ ] User visible changes (including notable bug fixes) are documented in whats-new.rst
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/6207/reactions",
    "total_count": 2,
    "+1": 2,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 pull
1046614317 PR_kwDOAMm_X84uL503 5948 Fix plot.line crash for data of shape (1, N) in _title_for_slice on format_item s-weigand 9513634 closed 0     2 2021-11-06T22:56:59Z 2021-11-08T18:40:08Z 2021-11-08T17:27:45Z CONTRIBUTOR   0 pydata/xarray/pulls/5948

Affected xarray versions 0.20.0+

When dependabot recently made a PR to update xarray to 0.20.0 our integration test CI failed with .... File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/xarray/plot/plot.py", line 447, in line ax.set_title(darray._title_for_slice()) File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/xarray/core/dataarray.py", line 3140, in _title_for_slice v=format_item(coord.values), File "/opt/hostedtoolcache/Python/3.8.12/x64/lib/python3.8/site-packages/xarray/core/formatting.py", line 146, in format_item return f"{x:.4}" TypeError: unsupported format string passed to numpy.ndarray.__format__

We use xarray.Dataarray.plot.line(x="<dim_name>") to plot data of shape (N, M) where N and M are >=1.

The crash is caused because the following line

https://github.com/pydata/xarray/blob/402a9b398868bd9bd385210138d6f8ea610c8c40/xarray/core/dataarray.py#L3136

allows arrays of shape () and (1,) to be passed into format_item, where both pass this check

https://github.com/pydata/xarray/blob/402a9b398868bd9bd385210138d6f8ea610c8c40/xarray/core/formatting.py#L145-L146

But f"{x:.4}" only works for arrays of shape () and crashes on arrays of shape (1,)

Before the check was https://github.com/pydata/xarray/blob/a78c1e0115d38cb4461fd1aba93334d440cff49c/xarray/core/formatting.py#L145-L146

Which didn't allow any arrays and caused the float formatting issue.

Code showing the differences ```python In [1]: import numpy as np In [2]: x = np.array(0.1) In [3]: x.shape Out[3]: () In [4]: np.issubdtype(type(x), np.floating) Out[4]: False In [5]: hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating) Out[5]: True In [6]: f"{x:.4}" Out[6]: '0.1' In [7]: f"{x.item():.4}" Out[7]: '0.1' In [8]: x = np.array([0.1]) In [9]: x.shape Out[9]: (1,) In [10]: np.issubdtype(type(x), np.floating) Out[10]: False In [11]: hasattr(x, "dtype") and np.issubdtype(x.dtype, np.floating) Out[11]: True In [12]: f"{x:.4}" --------------------------------------------------------------------------- TypeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_32644/2490801713.py in <module> ----> 1 f"{x:.4}" TypeError: unsupported format string passed to numpy.ndarray.__format__ In [13]: f"{x.item():.4}" Out[13]: '0.1' ```

I hope TestPlot1D was the correct place to put the test since the plot itself is 1D but the data which are plotted have a second dimension with size 1 (naming thing and where to put things... 😅).

  • [x] Tests added
  • [x] Passes pre-commit run --all-files
  • [x] User visible changes (including notable bug fixes) are documented in whats-new.rst

PS: Thanks for the awesome package ❤️

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/5948/reactions",
    "total_count": 1,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 1,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 pull

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 26.972ms · About: xarray-datasette