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

APIv2: pass user defined filename_or_obj to backends as is #4707

Merged
merged 5 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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