MCPcopy Create free account
hub / github.com/numpy/numpy / _write_array_header

Function _write_array_header

numpy/lib/format.py:414–447  ·  view source on GitHub ↗

Write the header for an array and returns the version used Parameters ---------- fp : filelike object d : dict This has the appropriate entries for writing its string representation to the header of the file. version : tuple or None None means use oldest

(fp, d, version=None)

Source from the content-addressed store, hash-verified

412
413
414def _write_array_header(fp, d, version=None):
415 """ Write the header for an array and returns the version used
416
417 Parameters
418 ----------
419 fp : filelike object
420 d : dict
421 This has the appropriate entries for writing its string representation
422 to the header of the file.
423 version : tuple or None
424 None means use oldest that works. Providing an explicit version will
425 raise a ValueError if the format does not allow saving this data.
426 Default: None
427 """
428 header = ["{"]
429 for key, value in sorted(d.items()):
430 # Need to use repr here, since we eval these when reading
431 header.append("'%s': %s, " % (key, repr(value)))
432 header.append("}")
433 header = "".join(header)
434
435 # Add some spare space so that the array header can be modified in-place
436 # when changing the array size, e.g. when growing it by appending data at
437 # the end.
438 shape = d['shape']
439 header += " " * ((GROWTH_AXIS_MAX_DIGITS - len(repr(
440 shape[-1 if d['fortran_order'] else 0]
441 ))) if len(shape) > 0 else 0)
442
443 if version is None:
444 header = _wrap_header_guess_version(header)
445 else:
446 header = _wrap_header(header, version)
447 fp.write(header)
448
449def write_array_header_1_0(fp, d):
450 """ Write the header for an array using the 1.0 format.

Callers 4

write_array_header_1_0Function · 0.85
write_array_header_2_0Function · 0.85
write_arrayFunction · 0.85
open_memmapFunction · 0.85

Calls 4

_wrap_headerFunction · 0.85
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected