MCPcopy Create free account
hub / github.com/PyTables/PyTables / _getnobjects

Method _getnobjects

tables/vlarray.py:467–503  ·  view source on GitHub ↗

Return the number of objects in a NumPy array.

(self, nparr: np.ndarray)

Source from the content-addressed store, hash-verified

465 return self._v_objectid
466
467 def _getnobjects(self, nparr: np.ndarray) -> int:
468 """Return the number of objects in a NumPy array."""
469 # Check for zero dimensionality array
470 zerodims = np.sum(np.array(nparr.shape) == 0)
471 if zerodims > 0:
472 # No objects to be added
473 return 0
474 shape = nparr.shape
475 atom_shape = self.atom.shape
476 shapelen = len(nparr.shape)
477 if isinstance(atom_shape, tuple):
478 atomshapelen = len(self.atom.shape)
479 else:
480 atom_shape = (self.atom.shape,)
481 atomshapelen = 1
482 diflen = shapelen - atomshapelen
483 if shape == atom_shape:
484 nobjects = 1
485 elif diflen == 1 and shape[diflen:] == atom_shape:
486 # Check if the leading dimensions are all ones
487 # if shape[:diflen-1] == (1,)*(diflen-1):
488 # nobjects = shape[diflen-1]
489 # shape = shape[diflen:]
490 # It's better to accept only inputs with the exact dimensionality
491 # i.e. a dimensionality only 1 element larger than atom
492 nobjects = shape[0]
493 shape = shape[1:]
494 elif atom_shape == (1,) and shapelen == 1:
495 # Case where shape = (N,) and shape_atom = 1 or (1,)
496 nobjects = shape[0]
497 else:
498 raise ValueError(
499 "The object '%s' is composed of elements with "
500 "shape '%s', which is not compatible with the "
501 "atom shape ('%s')." % (nparr, shape, atom_shape)
502 )
503 return nobjects
504
505 def get_enum(self) -> Enum:
506 """Get the enumerated type associated with this array.

Callers 2

appendMethod · 0.95
_assign_valuesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected