[Numpy-discussion] effect of shape=None (the default) in format.open_memmap
Tue Jul 6 21:03:37 CDT 2010
Hi, I'm trying to wrap my brain around the affect of leaving shape=None (the
default) in format.open_memmap. First, I get that it's only even seen if
the file is opened in write mode. Then, write_array_header_1_0 is called
with dict d as second parameter, w/, as near as I can see, d['shape'] still
= None. write_array_header_1_0 is a little opaque to me, but as near as I
can tell, shape = None is then written as is to the file's header. Here's
where things get a little worrisome/confusing. Looking ahead, the next
function in the source is read_array_header_1_0, in which we see the
following comment: "...The keys are strings 'shape' : tuple of int..." Then
later in the code we see:
# Sanity-check the values.
if (not isinstance(d['shape'], tuple) or
not numpy.all([isinstance(x, (int,long)) for x in d['shape']])):
msg = "shape is not valid: %r"
raise ValueError(msg % (d['shape'],))
Unless I'm missing something, if shape=None, this ValueError will be raised,
correct? So it appears as if the default value for shape in the original
function, open_memmap, will produce a header that would ultimately result in
a "defective" file, at least as far as read_array_header_1_0 is concerned.
A) Am I missing something (e.g., a numpy-wide default substitution for shape
if it happens to equal None) that results in this conclusion being
B) If I am correct, "feature" or "bug"?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion