Hierarchical datasets for Python with HDF5 library for managing extremely large amounts of data
PyTables provides a complete transaction system with undo/redo capabilities, allowing you to mark specific states, rollback changes, and maintain data integrity through ACID-compliant operations. This system is essential for collaborative workflows and error recovery.
class File:
def enable_undo(self, filters=None):
"""
Enable undo/redo functionality for the file.
Parameters:
- filters (Filters): Compression for undo log
"""
def disable_undo(self):
"""Disable undo/redo and remove transaction log."""
def is_undo_enabled(self):
"""
Check if undo/redo is enabled.
Returns:
bool: True if undo/redo is enabled
"""class File:
def mark(self, name=None):
"""
Create a transaction mark at current state.
Parameters:
- name (str): Optional name for the mark
Returns:
int: Mark identifier
"""
def undo(self, mark=None):
"""
Undo operations back to specified mark.
Parameters:
- mark (int or str): Mark to undo to (None for last mark)
"""
def redo(self, mark=None):
"""
Redo operations forward to specified mark.
Parameters:
- mark (int or str): Mark to redo to (None for next mark)
"""
def get_current_mark(self):
"""
Get current transaction mark.
Returns:
int: Current mark identifier
"""
def goto(self, mark):
"""
Go directly to specified mark.
Parameters:
- mark (int or str): Target mark identifier
"""class File:
def get_marks(self):
"""
Get list of all available marks.
Returns:
list: Mark identifiers and names
"""
def _undo_log(self):
"""Access to internal undo log for advanced operations."""import tables as tb
import numpy as np
with tb.open_file("transactional.h5", "w") as h5file:
# Enable transactions
h5file.enable_undo()
# Create initial data structure
table = h5file.create_table("/", "data", MyDescription)
h5file.mark("initial_structure")
# Add some data
for i in range(100):
row = table.row
row['id'] = i
row['value'] = i * 2.0
row.append()
table.flush()
h5file.mark("first_data_batch")
# Add more data
for i in range(100, 200):
row = table.row
row['id'] = i
row['value'] = i * 3.0
row.append()
table.flush()
h5file.mark("second_data_batch")
# Create additional structures
array = h5file.create_array("/", "lookup", np.arange(200))
h5file.mark("with_lookup_array")
# Something went wrong - undo to previous state
h5file.undo("second_data_batch")
# Check current state
print(f"Table rows: {table.nrows}") # Should be 100
print(f"Array exists: {'lookup' in h5file.root}") # Should be False
# Redo to restore array
h5file.redo("with_lookup_array")
# List all available marks
marks = h5file.get_marks()
print(f"Available marks: {marks}")Install with Tessl CLI
npx tessl i tessl/pypi-tables