File tree Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -156,10 +156,7 @@ def _repr_html_(self):
156
156
return formatting_html .array_repr (self )
157
157
158
158
def __format__ (self : Any , format_spec : str ) -> str :
159
- if not format_spec :
160
- # format without specifier falls backs to standard repr
161
- return formatting .array_repr (self )
162
- # else use numpy: scalars will print fine and arrays will raise
159
+ # we use numpy: scalars will print fine and arrays will raise
163
160
return self .values .__format__ (format_spec )
164
161
165
162
def _iter (self : Any ) -> Iterator [Any ]:
Original file line number Diff line number Diff line change @@ -415,15 +415,12 @@ def test_array_repr_variable(self) -> None:
415
415
416
416
def test_array_scalar_format (self ) -> None :
417
417
var = xr .DataArray (0 )
418
- assert var .__format__ ("" ) == "<xarray.DataArray ()> \n array(0) "
418
+ assert var .__format__ ("" ) == "0 "
419
419
assert var .__format__ ("d" ) == "0"
420
420
assert var .__format__ (".2f" ) == "0.00"
421
421
422
- var = xr .DataArray ([0 ])
423
- assert var .__format__ ("" ) == (
424
- "<xarray.DataArray (dim_0: 1)>\n array([0])"
425
- "\n Dimensions without coordinates: dim_0"
426
- )
422
+ var = xr .DataArray ([0.1 , 0.2 ])
423
+ assert var .__format__ ("" ) == "[0.1 0.2]"
427
424
with pytest .raises (TypeError ) as excinfo :
428
425
var .__format__ (".2f" )
429
426
assert "unsupported format string passed to" in str (excinfo .value )
You can’t perform that action at this time.
0 commit comments