Calculate the number of rows that will fit in a buffer.
(self, obj: np.ndarray)
| 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"""\ |
| 435 | The object ``{obj}`` is exceeding the maximum recommended rowsize ({maxrowsize} |
| 436 | bytes); be ready to see PyTables asking for *lots* of memory and |
| 437 | possibly slow I/O. You may want to reduce the rowsize by trimming the |
| 438 | value 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, |