Skip to content

Silently ignoring user passed engine key in some cases when opening file objects #4457

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

Closed
alexamici opened this issue Sep 24, 2020 · 0 comments · Fixed by #4458
Closed

Silently ignoring user passed engine key in some cases when opening file objects #4457

alexamici opened this issue Sep 24, 2020 · 0 comments · Fixed by #4458

Comments

@alexamici
Copy link
Collaborator

alexamici commented Sep 24, 2020

What happened:

When I open() a netCDF4 file and pass the file object to xr.open_dataset with engine='scipy' xarray silently ignores the value of the engine keyword and opens the file with h5netcdf. When opening an netCDF3 file with engine='h5netcdf' the scipy engine is used instead without warning.

What you expected to happen:

Silent autodetection of the engine is fine when passing engine=None, but it is very surprising when passing a value explicitly. I would have expected an exception or at least a warning.

Minimal Complete Verifiable Example:

>>> xr.open_dataset('netCDF4.nc', engine='scipy')
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[...]
TypeError: Error: netCDF4.nc is not a valid NetCDF 3 file
            If this is a NetCDF4 file, you may need to install the
            netcdf4 library, e.g.,

            $ pip install netcdf4

>>> fp = open('netCDF4.nc')
>>> xr.open_dataset(fp, engine='scipy')
<xarray.Dataset>
Dimensions:       (line: 41587, pixel: 17751)
Coordinates:
  * line          (line) int64 0 1 2 3 4 5 ... 41582 41583 41584 41585 41586
  * pixel         (pixel) int64 0 1 2 3 4 5 ... 17746 17747 17748 17749 17750
Data variables:
    phase         (line, pixel) float32 ...
Attributes:
    Conventions:             CF-1.7
    [...]
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.

2 participants