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

Method test03_copy

tables/tests/test_tables.py:5910–5994  ·  view source on GitHub ↗

Checking Table.copy() method (table larger than buffer)

(self)

Source from the content-addressed store, hash-verified

5908 self.assertEqual(table1.filters.fletcher32, table2.filters.fletcher32)
5909
5910 def test03_copy(self):
5911 """Checking Table.copy() method (table larger than buffer)"""
5912
5913 if common.verbose:
5914 print("\n", "-=" * 30)
5915 print("Running %s.test03_copy..." % self.__class__.__name__)
5916
5917 # Create a recarray exceeding buffers capability
5918 # This works, but takes too much CPU for a test
5919 # It is better to reduce the buffer size (table1.nrowsinbuf)
5920 # r=np.rec.array(b'aaaabbbbccccddddeeeeffffgggg'*20000,
5921 # formats='2i2,i4, (2,3)u2, (1,)f4, f8',shape=700)
5922 r = np.rec.array(
5923 b"aaaabbbbccccddddeeeeffffgggg" * 200,
5924 formats="2i2,i4, (2,3)u2, (1,)f4, f8",
5925 shape=7,
5926 aligned=self.aligned,
5927 )
5928 # Save it in a table:
5929 table1 = self.h5file.create_table(
5930 self.h5file.root, "table1", r, "title table1"
5931 )
5932
5933 if self.close:
5934 if common.verbose:
5935 print("(closing file version)")
5936 self._reopen(mode="a")
5937 table1 = self.h5file.root.table1
5938
5939 # Copy to another table in another group and other title
5940 group1 = self.h5file.create_group("/", "group1")
5941 table1.nrowsinbuf = 2 # small value of buffer
5942 table2 = table1.copy(group1, "table2", title="title table2")
5943 if self.close:
5944 if common.verbose:
5945 print("(closing file version)")
5946 self._reopen()
5947 table1 = self.h5file.root.table1
5948 table2 = self.h5file.root.group1.table2
5949
5950 if common.verbose:
5951 print("table1-->", table1.read())
5952 print("table2-->", table2.read())
5953 print("attrs table1-->", repr(table1.attrs))
5954 print("attrs table2-->", repr(table2.attrs))
5955
5956 # Check that all the elements are equal
5957 for row1 in table1:
5958 nrow = row1.nrow # current row
5959 for colname in table1.colnames:
5960 # self.assertTrue(allequal(row1[colname],
5961 # table2[nrow][colname]))
5962 self.assertTrue(
5963 common.allequal(
5964 row1[colname], table2.read(nrow, field=colname)[0]
5965 )
5966 )
5967

Callers

nothing calls this directly

Calls 6

create_groupMethod · 0.80
create_tableMethod · 0.45
_reopenMethod · 0.45
copyMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected