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

Method _calc_nrowsinbuf

tables/table.py:960–1000  ·  view source on GitHub ↗

Calculate the number of rows that fits on a PyTables buffer.

(self)

Source from the content-addressed store, hash-verified

958 self._autoindex = self.autoindex
959
960 def _calc_nrowsinbuf(self) -> int:
961 """Calculate the number of rows that fits on a PyTables buffer."""
962 params = self._v_file.params
963 # Compute the nrowsinbuf
964 rowsize = self.rowsize
965 buffersize = params["IO_BUFFER_SIZE"]
966 if rowsize != 0:
967 nrowsinbuf = buffersize // rowsize
968 # The number of rows in buffer needs to be an exact multiple of
969 # chunkshape[0] for queries using indexed columns.
970 # Fixes #319 and probably #409 too.
971 nrowsinbuf -= nrowsinbuf % self.chunkshape[0]
972 else:
973 nrowsinbuf = 1
974
975 # tableextension.pyx performs an assertion
976 # to make sure nrowsinbuf is greater than or
977 # equal to the chunksize.
978 # See gh-206 and gh-238
979 if self.chunkshape is not None:
980 if nrowsinbuf < self.chunkshape[0]:
981 nrowsinbuf = self.chunkshape[0]
982
983 # Safeguard against row sizes being extremely large
984 if nrowsinbuf == 0:
985 nrowsinbuf = 1
986 # If rowsize is too large, issue a Performance warning
987 maxrowsize = params["BUFFER_TIMES"] * buffersize
988 if rowsize > maxrowsize:
989 warnings.warn(
990 f"""\
991The Table ``{self._v_pathname}`` is exceeding the maximum recommended rowsize
992({maxrowsize} bytes);
993be ready to see PyTables asking for *lots* of memory and possibly slow
994I/O. You may want to reduce the rowsize by trimming the value of
995dimensions that are orthogonal (and preferably close) to the *main*
996dimension of this leave. Alternatively, in case you have specified a
997very small/large chunksize, you may want to increase/decrease it.""",
998 PerformanceWarning,
999 )
1000 return nrowsinbuf
1001
1002 def _getemptyarray(self, dtype: np.dtype) -> np.ndarray:
1003 # Acts as a cache for empty arrays

Callers 2

_g_createMethod · 0.95
_g_openMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected