Skip to content

Commit 8cf3ad7

Browse files
authored
Merge branch 'main' into async-dtreec
2 parents adac9b1 + 89a6349 commit 8cf3ad7

File tree

7 files changed

+53
-21
lines changed

7 files changed

+53
-21
lines changed

design_notes/flexible_indexes_notes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ In general explicit index creation should be preferred over implicit index creat
150150

151151
For which coordinates?
152152

153-
- A. only 1D coordinates with a name matching their dimension name
154-
- B. all 1D coordinates
153+
- 1A. only 1D coordinates with a name matching their dimension name
154+
- 1B. all 1D coordinates
155155

156156
When to create it?
157157

158-
- A. each time when a new Dataset/DataArray is created
159-
- B. only when we need it (i.e., when calling `.sel()` or `indexes`)
158+
- 2A. each time when a new Dataset/DataArray is created
159+
- 2B. only when we need it (i.e., when calling `.sel()` or `indexes`)
160160

161-
Options A and A are what Xarray currently does and may be the best choice considering that indexes could possibly be invalidated by coordinate mutation.
161+
Options 1A and 2A are what Xarray currently does and may be the best choice considering that indexes could possibly be invalidated by coordinate mutation.
162162

163163
Besides `pandas.Index`, other indexes currently supported in Xarray like `CFTimeIndex` could be built depending on the coordinate data type.
164164

doc/whats-new.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ Deprecations
3030
Bug Fixes
3131
~~~~~~~~~
3232

33+
- Fix ``.plot`` error when using positional args with ``col`` and
34+
``row`` (:issue:`11104` :pull:`11111`).
35+
By `Julia Signell <https://github.com/jsignell>`_.
3336
- Slightly amend `Xarray's Zarr Encoding Specification doc <https://docs.xarray.dev/en/latest/internals/zarr-encoding-spec.html>`_ for clarity, and provide a code comment in ``xarray.backends.zarr._get_zarr_dims_and_attrs`` referencing the doc (:issue:`8749` :pull:`11013`).
3437
By `Ewan Short <https://github.com/eshort0401>`_.
3538
- Fix silent data corruption when writing dask arrays to sharded Zarr stores.
3639
Dask chunk boundaries must now align with shard boundaries, not just internal
3740
Zarr chunk boundaries (:issue:`10831`).
3841

39-
4042
Documentation
4143
~~~~~~~~~~~~~
4244

xarray/backends/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def _chunk_ds(
266266
inline_array=inline_array,
267267
chunked_array_type=chunkmanager,
268268
from_array_kwargs=from_array_kwargs.copy(),
269+
just_use_token=True,
269270
)
270271
return backend_ds._replace(variables)
271272

xarray/plot/dataarray_plot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def step(
641641

642642
def hist(
643643
darray: DataArray,
644-
*args: Any,
644+
*,
645645
figsize: Iterable[float] | None = None,
646646
size: float | None = None,
647647
aspect: AspectOptions = None,
@@ -695,8 +695,6 @@ def hist(
695695
Additional keyword arguments to :py:func:`matplotlib:matplotlib.pyplot.hist`.
696696
697697
"""
698-
assert len(args) == 0
699-
700698
if darray.ndim == 0 or darray.size == 0:
701699
# TypeError to be consistent with pandas
702700
raise TypeError("No numeric data to plot.")
@@ -928,6 +926,7 @@ def newplotfunc(
928926
raise ValueError(msg)
929927
else:
930928
warnings.warn(msg, DeprecationWarning, stacklevel=2)
929+
del msg
931930
del args
932931

933932
if hue_style is not None:
@@ -1461,6 +1460,7 @@ def newplotfunc(
14611460
raise ValueError(msg)
14621461
else:
14631462
warnings.warn(msg, DeprecationWarning, stacklevel=2)
1463+
del msg
14641464
del args
14651465

14661466
# Decide on a default for the colorbar before facetgrids

xarray/plot/dataset_plot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def newplotfunc(
213213
raise ValueError(msg)
214214
else:
215215
warnings.warn(msg, DeprecationWarning, stacklevel=2)
216+
del msg
216217
del args
217218

218219
_is_facetgrid = kwargs.pop("_is_facetgrid", False)
@@ -752,7 +753,7 @@ def _temp_dataarray(ds: Dataset, y: Hashable, locals_: dict[str, Any]) -> DataAr
752753
@overload
753754
def scatter( # type: ignore[misc,unused-ignore] # None is hashable :(
754755
ds: Dataset,
755-
*args: Any,
756+
*,
756757
x: Hashable | None = None,
757758
y: Hashable | None = None,
758759
z: Hashable | None = None,
@@ -793,7 +794,7 @@ def scatter( # type: ignore[misc,unused-ignore] # None is hashable :(
793794
@overload
794795
def scatter(
795796
ds: Dataset,
796-
*args: Any,
797+
*,
797798
x: Hashable | None = None,
798799
y: Hashable | None = None,
799800
z: Hashable | None = None,
@@ -834,7 +835,7 @@ def scatter(
834835
@overload
835836
def scatter(
836837
ds: Dataset,
837-
*args: Any,
838+
*,
838839
x: Hashable | None = None,
839840
y: Hashable | None = None,
840841
z: Hashable | None = None,
@@ -875,7 +876,7 @@ def scatter(
875876
@_update_doc_to_dataset(dataarray_plot.scatter)
876877
def scatter(
877878
ds: Dataset,
878-
*args: Any,
879+
*,
879880
x: Hashable | None = None,
880881
y: Hashable | None = None,
881882
z: Hashable | None = None,

xarray/structure/chunks.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def _maybe_chunk(
7272
inline_array: bool = False,
7373
chunked_array_type: str | ChunkManagerEntrypoint | None = None,
7474
from_array_kwargs=None,
75+
just_use_token=False,
7576
) -> Variable:
7677
from xarray.namedarray.daskmanager import DaskManager
7778

@@ -83,14 +84,16 @@ def _maybe_chunk(
8384
chunked_array_type
8485
) # coerce string to ChunkManagerEntrypoint type
8586
if isinstance(chunked_array_type, DaskManager):
86-
from dask.base import tokenize
87-
88-
# when rechunking by different amounts, make sure dask names change
89-
# by providing chunks as an input to tokenize.
90-
# subtle bugs result otherwise. see GH3350
91-
# we use str() for speed, and use the name for the final array name on the next line
92-
token2 = tokenize(token or var._data, str(chunks))
93-
name2 = f"{name_prefix}{name}-{token2}"
87+
if not just_use_token:
88+
from dask.base import tokenize
89+
90+
# when rechunking by different amounts, make sure dask names change
91+
# by providing chunks as an input to tokenize.
92+
# subtle bugs result otherwise. see GH3350
93+
# we use str() for speed, and use the name for the final array name on the next line
94+
token = tokenize(token or var._data, str(chunks))
95+
96+
name2 = f"{name_prefix}{name}-{token}"
9497

9598
from_array_kwargs = utils.consolidate_dask_from_array_kwargs(
9699
from_array_kwargs,

xarray/tests/test_plot.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,14 @@ def test_slice_in_title_single_item_array(self) -> None:
834834
title = plt.gca().get_title()
835835
assert "d = [10.009]" == title
836836

837+
def test_warns_for_few_positional_args(self) -> None:
838+
with pytest.warns(DeprecationWarning, match="Using positional arguments"):
839+
self.darray.plot.scatter("period")
840+
841+
def test_raises_for_too_many_positional_args(self) -> None:
842+
with pytest.raises(ValueError, match="Using positional arguments"):
843+
self.darray.plot.scatter("period", "foo", "bar", "blue", {})
844+
837845

838846
class TestPlotStep(PlotTestCase):
839847
@pytest.fixture(autouse=True)
@@ -1730,6 +1738,19 @@ def test_colormap_error_norm_and_vmin_vmax(self) -> None:
17301738
with pytest.raises(ValueError):
17311739
self.darray.plot(norm=norm, vmax=2) # type: ignore[call-arg]
17321740

1741+
def test_plot_warns_for_2_positional_args(self) -> None:
1742+
da = xr.DataArray(
1743+
np.random.randn(2, 6, 6),
1744+
dims=("time", "x", "y"),
1745+
coords={"x": np.arange(6), "y": np.arange(6)},
1746+
)
1747+
with pytest.warns(DeprecationWarning, match="Using positional arguments"):
1748+
self.plotfunc(da, "x", "y", col="time")
1749+
1750+
def test_plot_raises_too_many_for_positional_args(self) -> None:
1751+
with pytest.raises(ValueError, match="Using positional arguments"):
1752+
self.plotmethod("x", "y", (12, 4))
1753+
17331754

17341755
@pytest.mark.slow
17351756
class TestContourf(Common2dMixin, PlotTestCase):
@@ -2890,6 +2911,10 @@ def test_bad_args(
28902911
x=x, y=y, hue=hue, add_legend=add_legend, add_colorbar=add_colorbar
28912912
)
28922913

2914+
def test_does_not_allow_positional_args(self) -> None:
2915+
with pytest.raises(TypeError, match="takes 1 positional argument"):
2916+
self.ds.plot.scatter("A", "B")
2917+
28932918
def test_datetime_hue(self) -> None:
28942919
ds2 = self.ds.copy()
28952920

0 commit comments

Comments
 (0)