def _display_metadata_html(self): header = f'<h4>climpred.{type(self).__name__}</h4>' display_html(header, raw=True) init_repr_str = dataset_repr(self._datasets['initialized']) init_repr_str = init_repr_str.replace('xarray.Dataset', 'Initialized Ensemble') display_html(init_repr_str, raw=True) if isinstance(self, HindcastEnsemble): if any(self._datasets['observations']): for key in self._datasets['observations']: obs_repr_str = dataset_repr( self._datasets['observations'][key]) obs_repr_str = obs_repr_str.replace( 'xarray.Dataset', f'Verification Data {key}') display_html(obs_repr_str, raw=True) elif isinstance(self, PerfectModelEnsemble): if any(self._datasets['control']): control_repr_str = dataset_repr(self._datasets['control']) control_repr_str = control_repr_str.replace( 'xarray.Dataset', 'Control Simulation') display_html(control_repr_str, raw=True) if any(self._datasets['uninitialized']): uninit_repr_str = dataset_repr(self._datasets['uninitialized']) uninit_repr_str = uninit_repr_str.replace('xarray.Dataset', 'Uninitialized') display_html(uninit_repr_str, raw=True) # better would be to aggregate repr_strs and then all return but this fails # TypeError: __repr__ returned non-string (type NoneType) # workaround return empty string return ''
def test_repr_of_dataset(dataset): formatted = fh.dataset_repr(dataset) # coords, attrs, and data_vars are expanded assert (formatted.count( "class='xr-section-summary-in' type='checkbox' checked>") == 3) assert "<U4" in formatted or ">U4" in formatted assert "<IA>" in formatted
def test_repr_of_nonstr_dataset(dataset) -> None: ds = dataset.copy() ds.attrs[1] = "Test value" ds[2] = ds["tmin"] formatted = fh.dataset_repr(ds) assert "<dt><span>1 :</span></dt><dd>Test value</dd>" in formatted assert "<div class='xr-var-name'><span>2</span>" in formatted
def test_repr_of_dataset(dataset) -> None: formatted = fh.dataset_repr(dataset) # coords, attrs, and data_vars are expanded assert (formatted.count( "class='xr-section-summary-in' type='checkbox' checked>") == 3) assert "<U4" in formatted or ">U4" in formatted assert "<IA>" in formatted with xr.set_options( display_expand_coords=False, display_expand_data_vars=False, display_expand_attrs=False, ): formatted = fh.dataset_repr(dataset) # coords, attrs, and data_vars are collapsed assert (formatted.count( "class='xr-section-summary-in' type='checkbox' checked>") == 0) assert "<U4" in formatted or ">U4" in formatted assert "<IA>" in formatted
def test_repr_of_multiindex(multiindex): formatted = fh.dataset_repr(multiindex) assert "(x)" in formatted
def test_short_data_repr_html_non_str_keys(dataset): ds = dataset.assign({2: lambda x: x["tmin"]}) fh.dataset_repr(ds)
def test_repr_text_fallback(dataset): formatted = fh.dataset_repr(dataset) # Just test that the "pre" block used for fallback to plain text is present. assert "<pre class='xr-text-repr-fallback'>" in formatted