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

Method _calc_nrowsinbuf

tables/expression.py:412–444  ·  view source on GitHub ↗

Calculate the number of rows that will fit in a buffer.

(self, obj: np.ndarray)

Source from the content-addressed store, hash-verified

410 # Although the next code is similar to the method in `Leaf`, it
411 # allows the use of pure NumPy objects.
412 def _calc_nrowsinbuf(self, obj: np.ndarray) -> int:
413 """Calculate the number of rows that will fit in a buffer."""
414 # Compute the rowsize for the *leading* dimension
415 shape_ = list(obj.shape)
416 if shape_:
417 shape_[0] = 1
418
419 rowsize = np.prod(shape_) * obj.dtype.itemsize
420
421 # Compute the nrowsinbuf
422 # Multiplying the I/O buffer size by 4 gives optimal results
423 # in my benchmarks with `tables.Expr` (see ``bench/poly.py``)
424 buffersize = IO_BUFFER_SIZE * 4
425 nrowsinbuf = buffersize // rowsize
426
427 # Safeguard against row sizes being extremely large
428 if nrowsinbuf == 0:
429 nrowsinbuf = 1
430 # If rowsize is too large, issue a Performance warning
431 maxrowsize = BUFFER_TIMES * buffersize
432 if rowsize > maxrowsize:
433 warnings.warn(
434 f"""\
435The object ``{obj}`` is exceeding the maximum recommended rowsize ({maxrowsize}
436bytes); be ready to see PyTables asking for *lots* of memory and
437possibly slow I/O. You may want to reduce the rowsize by trimming the
438value of dimensions that are orthogonal (and preferably close) to the
439*leading* dimension of this object.""",
440 PerformanceWarning,
441 stacklevel=2,
442 )
443
444 return nrowsinbuf
445
446 def _guess_shape(
447 self,

Callers 1

_get_infoMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected