Skip to content

Commit 71f848d

Browse files
shoyerXarray-Beam authors
authored and
Xarray-Beam authors
committed
[xarray-beam] fix docs & bug in make_template
Reusing dask.array names for arrays with different shapes was the indirect cause of the error on our docs pages. I've also updated the build dependencies for our docs to fix other build issues, and added a Python 3.11 run of our unit tests. Fixes #76 PiperOrigin-RevId: 536022594
1 parent d4cbb47 commit 71f848d

File tree

7 files changed

+35
-18
lines changed

7 files changed

+35
-18
lines changed

.github/workflows/ci-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.9", "3.10"]
19+
python-version: ["3.9", "3.10", "3.11"]
2020
steps:
2121
- name: Cancel previous
2222
uses: styfle/[email protected]

.readthedocs.yaml

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
version: 2
77

88
build:
9-
image: latest
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3.10"
1012

1113
# Build documentation in the docs/ directory with Sphinx
1214
sphinx:
1315
configuration: docs/conf.py
1416

15-
# Optionally set the version of Python and requirements required to build your docs
17+
# Optionally declare the Python requirements required to build your docs
1618
python:
17-
version: "3.8"
1819
install:
1920
- method: pip
2021
path: .

docs/requirements.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# doc requirements
22
Jinja2==3.1.2
3-
myst-nb==0.17.1
3+
myst-nb==0.17.2
44
myst-parser==0.18.1
5-
sphinx_rtd_theme==1.1.1
5+
sphinx_rtd_theme==1.2.1
66
sphinx==5.3.0
7-
scipy==1.10.0
7+
scipy==1.10.1
88

99
# xarray-beam requirements
10-
apache-beam==2.44.0
11-
dask==2023.1.0
12-
immutabledict==2.2.3
13-
numpy==1.22.4
10+
apache-beam==2.47.0
11+
dask==2023.5.1
12+
immutabledict==2.2.4
13+
numpy==1.24.3
1414
pandas==1.5.3
15-
pooch==1.6.0
16-
rechunker==0.5.0
17-
xarray==2023.1.0
18-
zarr==2.13.6
15+
pooch==1.7.0
16+
rechunker==0.5.1
17+
xarray==2023.5.0
18+
zarr==2.14.2

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
setuptools.setup(
4444
name='xarray-beam',
45-
version='0.6.0',
45+
version='0.6.1',
4646
license='Apache 2.0',
4747
author='Google LLC',
4848
author_email='[email protected]',

xarray_beam/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545
DatasetToZarr,
4646
)
4747

48-
__version__ = '0.6.0'
48+
__version__ = '0.6.1'

xarray_beam/_src/zarr.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,11 @@ def make_template(
130130

131131
# override the lazy variables
132132
delayed = dask.delayed(_raise_template_error)()
133-
name = 'make_template'
134133
for k, v in dataset.variables.items():
135134
if k in lazy_vars:
135+
# names of dask arrays are used for keeping track of results, so arrays
136+
# with the same name cannot have different shape or dtype
137+
name = f"make_template_{'x'.join(map(str, v.shape))}_{v.dtype}"
136138
result[k].data = dask.array.from_delayed(
137139
delayed, v.shape, v.dtype, name=name
138140
)

xarray_beam/_src/zarr_test.py

+14
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,20 @@ def test_infer_zarr_chunks(self):
337337
):
338338
xbeam._src.zarr._infer_zarr_chunks(dataset.chunk({'x': (3, 2, 1)}))
339339

340+
def test_chunks_to_zarr_docs_demo(self):
341+
# verify that the ChunksToChunk demo from our docs works
342+
data = np.random.RandomState(0).randn(2920, 25, 53)
343+
ds = xarray.Dataset({'temperature': (('time', 'lat', 'lon'), data)})
344+
chunks = {'time': 1000, 'lat': 25, 'lon': 53}
345+
temp_dir = self.create_tempdir().full_path
346+
(
347+
test_util.EagerPipeline()
348+
| xbeam.DatasetToChunks(ds, chunks)
349+
| xbeam.ChunksToZarr(temp_dir)
350+
)
351+
result = xarray.open_zarr(temp_dir)
352+
xarray.testing.assert_identical(result, ds)
353+
340354

341355
if __name__ == '__main__':
342356
absltest.main()

0 commit comments

Comments
 (0)