Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into groupby-aggs-using-…
Browse files Browse the repository at this point in the history
…numpy-groupies

* upstream/main:
  Check for py version instead of try/except when importing entry_points (pydata#5988)
  Add "see also" in to_dataframe docs (pydata#5978)
  Alternate method using inline css to hide regular html output in an untrusted notebook (pydata#5880)
  Fix mypy issue with entry_points (pydata#5979)
  Remove pre-commit auto update (pydata#5958)
  Do not change coordinate inplace when throwing error (pydata#5957)
  Create CITATION.cff (pydata#5956)
  • Loading branch information
dcherian committed Nov 15, 2021
2 parents 43ade8c + a883ed0 commit 553735e
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 51 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/ci-pre-commit-autoupdate.yaml

This file was deleted.

96 changes: 96 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Hoyer"
given-names: "Stephan"
orcid: "https://orcid.org/0000-0002-5207-0380"
- family-names: "Roos"
given-names: "Maximilian"
- family-names: "Joseph"
given-names: "Hamman"
orcid: "https://orcid.org/0000-0001-7479-8439"
- family-names: "Magin"
given-names: "Justus"
- family-names: "Cherian"
given-names: "Deepak"
orcid: "https://orcid.org/0000-0002-6861-8734"
- family-names: "Fitzgerald"
given-names: "Clark"
orcid: "https://orcid.org/0000-0003-3446-6389"
- family-names: "Hauser"
given-names: "Mathias"
orcid: "https://orcid.org/0000-0002-0057-4878"
- family-names: "Fujii"
given-names: "Keisuke"
orcid: "https://orcid.org/0000-0003-0390-9984"
- family-names: "Maussion"
given-names: "Fabien"
orcid: "https://orcid.org/0000-0002-3211-506X"
- family-names: "Imperiale"
given-names: "Guido"
- family-names: "Clark"
given-names: "Spencer"
orcid: "https://orcid.org/0000-0001-5595-7895"
- family-names: "Kleeman"
given-names: "Alex"
- family-names: "Nicholas"
given-names: "Thomas"
orcid: "https://orcid.org/0000-0002-2176-0530"
- family-names: "Kluyver"
given-names: "Thomas"
orcid: "https://orcid.org/0000-0003-4020-6364"
- family-names: "Westling"
given-names: "Jimmy"
- family-names: "Munroe"
given-names: "James"
orcid: "https://orcid.org/0000-0001-9098-6309"
- family-names: "Amici"
given-names: "Alessandro"
orcid: "https://orcid.org/0000-0002-1778-4505"
- family-names: "Barghini"
given-names: "Aureliana"
- family-names: "Banihirwe"
given-names: "Anderson"
orcid: "https://orcid.org/0000-0001-6583-571X"
- family-names: "Bell"
given-names: "Ray"
orcid: "https://orcid.org/0000-0003-2623-0587"
- family-names: "Hatfield-Dodds"
given-names: "Zac"
orcid: "https://orcid.org/0000-0002-8646-8362"
- family-names: "Abernathey"
given-names: "Ryan"
orcid: "https://orcid.org/0000-0001-5999-4917"
- family-names: "Bovy"
given-names: "Benoît"
- family-names: "Omotani"
given-names: "John"
orcid: "https://orcid.org/0000-0002-3156-8227"
- family-names: "Mühlbauer"
given-names: "Kai"
orcid: "https://orcid.org/0000-0001-6599-1034"
- family-names: "Roszko"
given-names: "Maximilian K."
orcid: "https://orcid.org/0000-0001-9424-2526"
- family-names: "Wolfram"
given-names: "Phillip J."
orcid: "https://orcid.org/0000-0001-5971-4241"
title: "xarray"
doi: 10.5281/zenodo.598201
url: "https://github.com/pydata/xarray"
preferred-citation:
type: article
authors:
- family-names: "Hoyer"
given-names: "Stephan"
orcid: "https://orcid.org/0000-0002-5207-0380"
- family-names: "Joseph"
given-names: "Hamman"
orcid: "https://orcid.org/0000-0001-7479-8439"
doi: "10.5334/jors.148"
journal: "Journal of Open Research Software"
month: 4
title: "xarray: N-D labeled Arrays and Datasets in Python"
volume: 5
issue: 1
year: 2017
7 changes: 4 additions & 3 deletions xarray/backends/plugins.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import functools
import inspect
import itertools
import sys
import warnings

from .common import BACKEND_ENTRYPOINTS, BackendEntrypoint

try:
if sys.version_info >= (3, 8):
from importlib.metadata import entry_points
except ImportError:
else:
# if the fallback library is missing, we are doomed.
from importlib_metadata import entry_points # type: ignore[no-redef]
from importlib_metadata import entry_points


STANDARD_BACKENDS_ORDER = ["netcdf4", "h5netcdf", "scipy"]
Expand Down
9 changes: 7 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2726,9 +2726,11 @@ def to_dataframe(
"""Convert this array and its coordinates into a tidy pandas.DataFrame.
The DataFrame is indexed by the Cartesian product of index coordinates
(in the form of a :py:class:`pandas.MultiIndex`).
(in the form of a :py:class:`pandas.MultiIndex`). Other coordinates are
included as columns in the DataFrame.
Other coordinates are included as columns in the DataFrame.
For 1D and 2D DataArrays, see also :py:func:`DataArray.to_pandas` which
doesn't rely on a MultiIndex to build the DataFrame.
Parameters
----------
Expand All @@ -2750,6 +2752,9 @@ def to_dataframe(
result
DataArray as a pandas DataFrame.
See also
--------
DataArray.to_pandas
"""
if name is None:
name = self.name
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _obj_repr(obj, header_components, sections):
"<div>"
f"{icons_svg}<style>{css_style}</style>"
f"<pre class='xr-text-repr-fallback'>{escape(repr(obj))}</pre>"
"<div class='xr-wrap' hidden>"
"<div class='xr-wrap' style='display:none'>"
f"{header}"
f"<ul class='xr-sections'>{sections}</ul>"
"</div>"
Expand Down
5 changes: 5 additions & 0 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,11 @@ def name(self):
def name(self, value):
raise AttributeError("cannot modify name of IndexVariable in-place")

def _inplace_binary_op(self, other, f):
raise TypeError(
"Values of an IndexVariable are immutable and can not be modified inplace"
)


# for backwards compatibility
Coordinate = utils.alias(IndexVariable, "Coordinate")
Expand Down
2 changes: 1 addition & 1 deletion xarray/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ body.vscode-dark {
}

.xr-wrap {
display: block;
display: block !important;
min-width: 300px;
max-width: 700px;
}
Expand Down
12 changes: 12 additions & 0 deletions xarray/tests/test_dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,18 @@ def test_inplace_math_basics(self):
assert_array_equal(b.values, x)
assert source_ndarray(b.values) is x

def test_inplace_math_error(self):
data = np.random.rand(4)
times = np.arange(4)
foo = DataArray(data, coords=[times], dims=["time"])
b = times.copy()
with pytest.raises(
TypeError, match=r"Values of an IndexVariable are immutable"
):
foo.coords["time"] += 1
# Check error throwing prevented inplace operation
assert_array_equal(foo.coords["time"], b)

def test_inplace_math_automatic_alignment(self):
a = DataArray(range(5), [("x", range(5))])
b = DataArray(range(1, 6), [("x", range(1, 6))])
Expand Down
8 changes: 8 additions & 0 deletions xarray/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,14 @@ def test_inplace_math(self):
with pytest.raises(ValueError, match=r"dimensions cannot change"):
v += Variable("y", np.arange(5))

def test_inplace_math_error(self):
x = np.arange(5)
v = IndexVariable(["x"], x)
with pytest.raises(
TypeError, match=r"Values of an IndexVariable are immutable"
):
v += 1

def test_reduce(self):
v = Variable(["x", "y"], self.d, {"ignored": "attributes"})
assert_identical(v.reduce(np.std, "x"), Variable(["y"], self.d.std(axis=0)))
Expand Down

0 comments on commit 553735e

Please sign in to comment.