Skip to content

Added get_options method #5716

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

Merged
merged 8 commits into from
Sep 4, 2021
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
1 change: 1 addition & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Top-level functions
map_blocks
show_versions
set_options
get_options
unify_chunks

Dataset
Expand Down
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ v0.19.1 (unreleased)

New Features
~~~~~~~~~~~~
- Added a :py:func:`get_options` method to xarray's root namespace (:issue:`5698`, :pull:`5716`)
By `Pushkar Kopparla <https://github.com/pkopparla>`_.
- Xarray now does a better job rendering variable names that are long LaTeX sequences when plotting (:issue:`5681`, :pull:`5682`).
By `Tomas Chor <https://github.com/tomchor>`_.
- Add a option to disable the use of ``bottleneck`` (:pull:`5560`)
Expand Down
3 changes: 2 additions & 1 deletion xarray/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .core.dataset import Dataset
from .core.extensions import register_dataarray_accessor, register_dataset_accessor
from .core.merge import Context, MergeError, merge
from .core.options import set_options
from .core.options import get_options, set_options
from .core.parallel import map_blocks
from .core.variable import Coordinate, IndexVariable, Variable, as_variable
from .util.print_versions import show_versions
Expand Down Expand Up @@ -57,6 +57,7 @@
"cov",
"corr",
"full_like",
"get_options",
"infer_freq",
"load_dataarray",
"load_dataset",
Expand Down
14 changes: 14 additions & 0 deletions xarray/core/options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
import warnings

from .utils import FrozenDict

# TODO: Remove this check once python 3.7 is not supported:
if sys.version_info >= (3, 8):
from typing import TYPE_CHECKING, Literal, TypedDict, Union
Expand Down Expand Up @@ -269,3 +271,15 @@ def __enter__(self):

def __exit__(self, type, value, traceback):
self._apply_update(self.old)


def get_options():
"""
Get options for xarray.

See Also
----------
set_options

"""
return FrozenDict(OPTIONS)
11 changes: 11 additions & 0 deletions xarray/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,14 @@ def test_display_dataarray_style_html(self):
html = da._repr_html_()
assert html.startswith("<div>")
assert "#x27;nested&#x27;" in html


@pytest.mark.parametrize(
"set_value",
[("left"), ("exact")],
)
def test_get_options_retention(set_value):
"""Test to check if get_options will return changes made by set_options"""
with xarray.set_options(arithmetic_join=set_value):
get_options = xarray.get_options()
assert get_options["arithmetic_join"] == set_value