Skip to content
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
2 changes: 1 addition & 1 deletion xarray_beam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@
DatasetToZarr as DatasetToZarr,
)

__version__ = '0.11.4' # automatically synchronized to pyproject.toml
__version__ = '0.11.5' # automatically synchronized to pyproject.toml
7 changes: 5 additions & 2 deletions xarray_beam/_src/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,10 @@ def chunk_count(self) -> int:
)

def __repr__(self):
base = repr(self.template)
template_repr = repr(self.template)
# replace dask.array reprs with ..., both for the sake of brevity and
# because the dask chunks are not the same as the Dataset chunks.
template_repr = re.sub(r'dask.array\<.*\>', '...', template_repr)
chunks_str = ', '.join(
[f'{k}: {v}' for k, v in self.chunks.items()]
+ [f'split_vars={self.split_vars}']
Expand All @@ -551,7 +554,7 @@ def __repr__(self):
f'PTransform: {self._ptransform}\n'
f'Chunks: {chunk_size} ({chunks_str})\n'
f'Template: {total_size} ({chunk_count} chunk{plural})\n'
+ textwrap.indent('\n'.join(base.split('\n')[1:]), ' ' * 4)
+ textwrap.indent('\n'.join(template_repr.split('\n')[1:]), ' ' * 4)
)

@classmethod
Expand Down
23 changes: 13 additions & 10 deletions xarray_beam/_src/dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import re
import textwrap

from absl.testing import absltest
from absl.testing import parameterized
import apache_beam as beam
import numpy as np
import pandas as pd
import xarray
import xarray_beam as xbeam
from xarray_beam._src import dataset as xbeam_dataset
Expand Down Expand Up @@ -475,16 +475,19 @@ class DatasetTest(test_util.TestCase):

def test_repr(self):
ds = xarray.Dataset({'foo': ('x', np.arange(10))})
beam_ds = xbeam.Dataset.from_xarray(ds, {'x': 5})
self.assertRegex(
beam_ds = xbeam.Dataset.from_xarray(ds, {'x': 5}, label='my_label')
self.assertEqual(
repr(beam_ds),
re.escape(
'<xarray_beam.Dataset>\n'
'PTransform: <DatasetToChunks>\n'
'Chunks: 40B (x: 5, split_vars=False)\n'
'Template: 80B (2 chunks)\n'
' Dimensions:'
).replace('DatasetToChunks', 'DatasetToChunks.*'),
textwrap.dedent("""\
<xarray_beam.Dataset>
PTransform: <DatasetToChunks(PTransform) label=[my_label]>
Chunks: 40B (x: 5, split_vars=False)
Template: 80B (2 chunks)
Dimensions: (x: 10)
Dimensions without coordinates: x
Data variables:
foo (x) int64 80B ...
""").strip(),
)

def test_from_ptransform(self):
Expand Down
Loading