@@ -196,8 +196,8 @@ def format_array_flat(items_ndarray, max_width):
196
196
return pprint_str
197
197
198
198
199
- def _summarize_var_or_coord (name , var , col_width , show_values = True ,
200
- marker = ' ' , max_width = None ):
199
+ def summarize_variable (name , var , col_width , show_values = True ,
200
+ marker = ' ' , max_width = None ):
201
201
if max_width is None :
202
202
max_width = OPTIONS ['display_width' ]
203
203
first_col = pretty_print (u' %s %s ' % (marker , name ), col_width )
@@ -208,6 +208,8 @@ def _summarize_var_or_coord(name, var, col_width, show_values=True,
208
208
front_str = u'%s%s%s ' % (first_col , dims_str , var .dtype )
209
209
if show_values :
210
210
values_str = format_array_flat (var , max_width - len (front_str ))
211
+ elif isinstance (var .data , dask_array_type ):
212
+ values_str = short_dask_repr (var , show_dtype = False )
211
213
else :
212
214
values_str = u'...'
213
215
@@ -222,38 +224,29 @@ def _summarize_coord_multiindex(coord, col_width, marker):
222
224
def _summarize_coord_levels (coord , col_width , marker = u'-' ):
223
225
relevant_coord = coord [:30 ]
224
226
return u'\n ' .join (
225
- [_summarize_var_or_coord (lname ,
226
- relevant_coord .get_level_variable (lname ),
227
- col_width , marker = marker )
227
+ [summarize_variable (lname ,
228
+ relevant_coord .get_level_variable (lname ),
229
+ col_width , marker = marker )
228
230
for lname in coord .level_names ])
229
231
230
232
231
- def _not_remote (var ):
232
- """Helper function to identify if array is positively identifiable as
233
- coming from a remote source.
234
- """
235
- source = var .encoding .get ('source' )
236
- if source and source .startswith ('http' ) and not var ._in_memory :
237
- return False
238
- return True
239
-
240
-
241
- def summarize_var (name , var , col_width ):
242
- show_values = _not_remote (var )
243
- return _summarize_var_or_coord (name , var , col_width , show_values )
233
+ def summarize_datavar (name , var , col_width ):
234
+ show_values = var ._in_memory
235
+ return summarize_variable (name , var .variable , col_width , show_values )
244
236
245
237
246
238
def summarize_coord (name , var , col_width ):
247
239
is_index = name in var .dims
248
- show_values = is_index or _not_remote ( var )
240
+ show_values = var . _in_memory
249
241
marker = u'*' if is_index else u' '
250
242
if is_index :
251
243
coord = var .variable .to_index_variable ()
252
244
if coord .level_names is not None :
253
245
return u'\n ' .join (
254
246
[_summarize_coord_multiindex (coord , col_width , marker ),
255
247
_summarize_coord_levels (coord , col_width )])
256
- return _summarize_var_or_coord (name , var , col_width , show_values , marker )
248
+ return summarize_variable (
249
+ name , var .variable , col_width , show_values , marker )
257
250
258
251
259
252
def summarize_attr (key , value , col_width = None ):
@@ -307,7 +300,7 @@ def _mapping_repr(mapping, title, summarizer, col_width=None):
307
300
308
301
309
302
data_vars_repr = functools .partial (_mapping_repr , title = u'Data variables' ,
310
- summarizer = summarize_var )
303
+ summarizer = summarize_datavar )
311
304
312
305
313
306
attrs_repr = functools .partial (_mapping_repr , title = u'Attributes' ,
@@ -370,6 +363,19 @@ def short_array_repr(array):
370
363
return repr (array )
371
364
372
365
366
+ def short_dask_repr (array , show_dtype = True ):
367
+ """Similar to dask.array.DataArray.__repr__, but without
368
+ redundant information that's already printed by the repr
369
+ function of the xarray wrapper.
370
+ """
371
+ chunksize = tuple (c [0 ] for c in array .chunks )
372
+ if show_dtype :
373
+ return 'dask.array<shape=%s, dtype=%s, chunksize=%s>' % (
374
+ array .shape , array .dtype , chunksize )
375
+ else :
376
+ return 'dask.array<shape=%s, chunksize=%s>' % (array .shape , chunksize )
377
+
378
+
373
379
def array_repr (arr ):
374
380
# used for DataArray, Variable and IndexVariable
375
381
if hasattr (arr , 'name' ) and arr .name is not None :
@@ -381,7 +387,7 @@ def array_repr(arr):
381
387
% (type (arr ).__name__ , name_str , dim_summary (arr ))]
382
388
383
389
if isinstance (getattr (arr , 'variable' , arr )._data , dask_array_type ):
384
- summary .append (repr (arr . data ))
390
+ summary .append (short_dask_repr (arr ))
385
391
elif arr ._in_memory or arr .size < 1e5 :
386
392
summary .append (short_array_repr (arr .values ))
387
393
else :
0 commit comments