Calculate the number of rows that fits on a PyTables buffer.
(self)
| 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"""\ |
| 991 | The Table ``{self._v_pathname}`` is exceeding the maximum recommended rowsize |
| 992 | ({maxrowsize} bytes); |
| 993 | be ready to see PyTables asking for *lots* of memory and possibly slow |
| 994 | I/O. You may want to reduce the rowsize by trimming the value of |
| 995 | dimensions that are orthogonal (and preferably close) to the *main* |
| 996 | dimension of this leave. Alternatively, in case you have specified a |
| 997 | very 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 |