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

Method test04d_delete

tables/tests/test_tables.py:1886–1983  ·  view source on GitHub ↗

Checking whether removing rows several times at once is working.

(self)

Source from the content-addressed store, hash-verified

1884 self.assertEqual(result[:10], result2)
1885
1886 def test04d_delete(self):
1887 """Checking whether removing rows several times at once is working."""
1888
1889 if common.verbose:
1890 print("\n", "-=" * 30)
1891 print("Running %s.test04d_delete..." % self.__class__.__name__)
1892
1893 # Create an instance of an HDF5 Table
1894 self.h5file = tb.open_file(self.h5fname, "a")
1895 table = self.h5file.get_node("/table0")
1896
1897 # Read the records and select the ones with "var2" column less than 20
1898 result = [r["var2"] for r in table if r["var2"] < 20]
1899
1900 nrows = table.nrows
1901 nrowsinbuf = table.nrowsinbuf
1902 table.nrowsinbuf = 6 # small value of the buffer
1903 # Delete some rows
1904 table.remove_rows(10, 15)
1905 # It's necessary to restore the value of buffer to use the row object
1906 # afterwards...
1907 table.nrowsinbuf = nrowsinbuf
1908
1909 # Append some rows
1910 row = table.row
1911 for i in range(10, 15):
1912 row["var1"] = "%04d" % (self.appendrows - i)
1913 # This line gives problems on Windows. Why?
1914 # row['var7'] = row['var1'][-1]
1915 row["var2"] = i
1916 row["var3"] = i % self.maxshort
1917 if isinstance(row["var4"], np.ndarray):
1918 row["var4"] = [float(i), float(i * i)]
1919 else:
1920 row["var4"] = float(i)
1921 if isinstance(row["var8"], np.ndarray):
1922 row["var8"] = [0, 1]
1923 else:
1924 row["var8"] = 1
1925 if isinstance(row["var9"], np.ndarray):
1926 row["var9"] = [0.0 + float(i) * 1j, float(i) + 0.0j]
1927 else:
1928 row["var9"] = float(i) + 0.0j
1929 if isinstance(row["var10"], np.ndarray):
1930 row["var10"] = [float(i) + 0.0j, 1.0 + float(i) * 1j]
1931 else:
1932 row["var10"] = 1.0 + float(i) * 1j
1933 if isinstance(row["var5"], np.ndarray):
1934 row["var5"] = np.array((float(i),) * 4)
1935 else:
1936 row["var5"] = float(i)
1937 if hasattr(tb, "Float16Col"):
1938 if isinstance(row["var11"], np.ndarray):
1939 row["var11"] = np.array((float(i),) * 4)
1940 else:
1941 row["var11"] = float(i)
1942 if hasattr(tb, "Float96Col"):
1943 if isinstance(row["var12"], np.ndarray):

Callers

nothing calls this directly

Calls 4

remove_rowsMethod · 0.80
get_nodeMethod · 0.45
appendMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected