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

Method append

tables/table.py:2333–2401  ·  view source on GitHub ↗

Append a sequence of rows to the end of the table. The rows argument may be any object which can be converted to a structured array compliant with the table structure (otherwise, a ValueError is raised). This includes NumPy structured arrays, lists of tuples or arra

(self, rows: list | np.ndarray)

Source from the content-addressed store, hash-verified

2331 self._mark_columns_as_dirty(self.colpathnames)
2332
2333 def append(self, rows: list | np.ndarray) -> None:
2334 """Append a sequence of rows to the end of the table.
2335
2336 The rows argument may be any object which can be converted to
2337 a structured array compliant with the table structure
2338 (otherwise, a ValueError is raised). This includes NumPy
2339 structured arrays, lists of tuples or array records, and a
2340 string or Python buffer.
2341
2342 Examples
2343 --------
2344 ::
2345
2346 import tables as tb
2347
2348 class Particle(tb.IsDescription):
2349 name = tb.StringCol(16, pos=1) # 16-character String
2350 lati = tb.IntCol(pos=2) # integer
2351 longi = tb.IntCol(pos=3) # integer
2352 pressure = tb.Float32Col(pos=4) # float (single-precision)
2353 temperature = tb.FloatCol(pos=5) # double (double-precision)
2354
2355 fileh = tb.open_file('test4.h5', mode='w')
2356 table = fileh.create_table(fileh.root, 'table', Particle,
2357 "A table")
2358
2359 # Append several rows in only one call
2360 table.append([("Particle: 10", 10, 0, 10 * 10, 10**2),
2361 ("Particle: 11", 11, -1, 11 * 11, 11**2),
2362 ("Particle: 12", 12, -2, 12 * 12, 12**2)])
2363 fileh.close()
2364
2365 """
2366 self._g_check_open()
2367 self._v_file._check_writable()
2368
2369 if not self._chunked:
2370 raise HDF5ExtError(
2371 "You cannot append rows to a non-chunked table.", h5bt=False
2372 )
2373
2374 if (
2375 hasattr(rows, "dtype")
2376 and not self.description._v_is_nested
2377 and rows.dtype == self.dtype
2378 ):
2379 # Shortcut for compliant arrays
2380 # (for some reason, not valid for nested types)
2381 wbuf_ra = rows
2382 else:
2383 # Try to convert the object into a recarray compliant with table
2384 try:
2385 iflavor = flavor_of(rows)
2386 if iflavor != "python":
2387 rows = array_as_internal(rows, iflavor)
2388 # Works for Python structures and always copies the original,
2389 # so the resulting object is safe for in-place conversion.
2390 wbuf_ra = np.rec.array(rows, dtype=self._v_dtype)

Callers 15

create_tableMethod · 0.95
runMethod · 0.45
get_default_dirsFunction · 0.45
setup.pyFile · 0.45
add_tableFunction · 0.45
add_cacheFunction · 0.45
save2Function · 0.45
get_cacheMethod · 0.45
__getitem__Method · 0.45
nctoh5.pyFile · 0.45
_generate_col_classesFunction · 0.45
__init__Method · 0.45

Calls 6

_save_buffered_rowsMethod · 0.95
HDF5ExtErrorClass · 0.85
flavor_ofFunction · 0.85
array_as_internalFunction · 0.85
_g_check_openMethod · 0.80
_check_writableMethod · 0.80

Tested by 15

fill_tableFunction · 0.36
test_methodFunction · 0.36
suiteFunction · 0.36
populateFileMethod · 0.36
test_with_compressionMethod · 0.36
test01a_StringMethod · 0.36
test01b_StringMethod · 0.36
test02a_intMethod · 0.36
test02b_intMethod · 0.36
test03a_intMethod · 0.36