Skip to content

Commit

Permalink
APIv2: pass user defined filename_or_obj to backends as is (#4707)
Browse files Browse the repository at this point in the history
* Pass filename_or_obj as passed by the user to beckends

* Code style

* Fix autodetection to also accept pathlib.Path

* ensure _get_default_engine get an str object
  • Loading branch information
alexamici authored Dec 22, 2020
1 parent de3f275 commit 7e2e22a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 4 additions & 3 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pathlib
import warnings
from glob import glob
from io import BytesIO
Expand Down Expand Up @@ -144,7 +145,7 @@ def _get_engine_from_magic_number(filename_or_obj):
return engine


def _get_default_engine(path, allow_remote=False):
def _get_default_engine(path: str, allow_remote: bool = False):
if allow_remote and is_remote_uri(path):
engine = _get_default_engine_remote_uri()
elif is_grib_path(path):
Expand All @@ -159,8 +160,8 @@ def _get_default_engine(path, allow_remote=False):
def _autodetect_engine(filename_or_obj):
if isinstance(filename_or_obj, AbstractDataStore):
engine = "store"
elif isinstance(filename_or_obj, str):
engine = _get_default_engine(filename_or_obj, allow_remote=True)
elif isinstance(filename_or_obj, (str, pathlib.Path)):
engine = _get_default_engine(str(filename_or_obj), allow_remote=True)
else:
engine = _get_engine_from_magic_number(filename_or_obj)
return engine
Expand Down
3 changes: 0 additions & 3 deletions xarray/backends/apiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .api import (
_autodetect_engine,
_get_backend_cls,
_normalize_path,
_protect_dataset_variables_inplace,
)

Expand Down Expand Up @@ -245,8 +244,6 @@ def open_dataset(
if backend_kwargs is None:
backend_kwargs = {}

filename_or_obj = _normalize_path(filename_or_obj)

if engine is None:
engine = _autodetect_engine(filename_or_obj)

Expand Down

0 comments on commit 7e2e22a

Please sign in to comment.