MCPcopy Index your code
hub / github.com/PyTables/PyTables / _read

Method _read

tables/table.py:1921–2003  ·  view source on GitHub ↗

Read a range of rows and return an in-memory object.

(
        self,
        start: int,
        stop: int,
        step: int,
        field: str | None = None,
        out: np.ndarray | None = None,
    )

Source from the content-addressed store, hash-verified

1919 return self.iterrows()
1920
1921 def _read(
1922 self,
1923 start: int,
1924 stop: int,
1925 step: int,
1926 field: str | None = None,
1927 out: np.ndarray | None = None,
1928 ) -> np.ndarray:
1929 """Read a range of rows and return an in-memory object."""
1930 select_field = None
1931 if field:
1932 if field not in self.coldtypes:
1933 if field in self.description._v_names:
1934 # Remember to select this field
1935 select_field = field
1936 field = None
1937 else:
1938 raise KeyError(
1939 ("Field {} not found in table " "{}").format(
1940 field, self
1941 )
1942 )
1943 else:
1944 # The column hangs directly from the top
1945 dtype_field = self.coldtypes[field]
1946
1947 # Return a rank-0 array if start > stop
1948 if (start >= stop and 0 < step) or (start <= stop and 0 > step):
1949 if field is None:
1950 nra = self._get_container(0)
1951 return nra
1952 return np.empty(shape=0, dtype=dtype_field)
1953
1954 nrows = len(range(start, stop, step))
1955
1956 if out is None:
1957 # Compute the shape of the resulting column object
1958 if field:
1959 # Create a container for the results
1960 result = np.empty(shape=nrows, dtype=dtype_field)
1961 else:
1962 # Recarray case
1963 result = self._get_container(nrows)
1964 else:
1965 # there is no fast way to byteswap, since different columns may
1966 # have different byteorders
1967 if not out.dtype.isnative:
1968 raise ValueError(
1969 "output array must be in system's byteorder "
1970 "or results will be incorrect"
1971 )
1972 if field:
1973 bytes_required = dtype_field.itemsize * nrows
1974 else:
1975 bytes_required = self.rowsize * nrows
1976 if bytes_required != out.nbytes:
1977 raise ValueError(
1978 f"output array size invalid, got {out.nbytes}"

Callers 4

readMethod · 0.95
modify_columnMethod · 0.95
modify_columnsMethod · 0.95
_add_rows_to_indexMethod · 0.95

Calls 1

_get_containerMethod · 0.95

Tested by

no test coverage detected