<jupyter_start><jupyter_text>Using `tables_io.read`, `tables_io.write` and `tables_io.convert`These functions can be used to read and write single tables and to convert them to different formatsThe Tables can be in any of the formats that `tables_io` supports, see more on that in the notebook below.Let's have a look<jupyter_code># Standard imports
import os
import numpy as np
import tables_io
from tables_io.testUtils import make_test_data
# make several tables and grab one
tables = make_test_data()
data = tables['data']
data
data_np = tables_io.convert(data, tables_io.types.NUMPY_DICT)
data_np
data_pd = tables_io.convert(data, tables_io.types.PD_DATAFRAME)
data_pd<jupyter_output><empty_output><jupyter_text>File IO with `tables_io`We can write tables into several different formats.  These include:1. fits:  Writing `astropy.table.Table` objects to FITS files (with the suffix 'fits')2. hf5: Writing `astropy.table.Table` objects to HDF5 files (with the suffix 'hf5')3. hfd5: Writing `numpy.array` objects to HDF5 files (with the suffix 'hdf5')4. h5: Writing `pandas.DataFrame` objects to HDF5 files (with the suffix 'h5')5. pq: Writing `pandas.DataFrame` objects to parquet files (with the suffix 'pq')Also, each table type has a 'native' format that we use as a default.  Setting the `fmt` to `None` in function calls will typically use the 'native' format.<jupyter_code>all_fmts = list(tables_io.types.FILE_FORMAT_SUFFIXS.keys()) + [None]
print(all_fmts)<jupyter_output><empty_output><jupyter_text>Ok let's write the data to different files<jupyter_code>for fmt in all_fmts:
    if fmt is None:
        basename = 'test_single_native'
    else:
        basename = 'test_single_out'
    print("Writing to %s using format %s" % (basename, fmt))
    try:
        os.unlink('%s.%s' % (basename, fmt))
    except:
        pass
    try:
        tables_io.write(data, basename, fmt)
    except ImportError as msg:
        print("Skipping format %s because %s" % (fmt, msg))
! ls test_single_*<jupyter_output><empty_output><jupyter_text>Ok, now let's read things back<jupyter_code>data_r_fits = tables_io.read("test_single_out.fits")
data_r_fits
data_r_hdf5 = tables_io.read("test_single_out.hdf5")
data_r_hdf5
data_r_hf5 = tables_io.read("test_single_out.hf5")
data_r_hf5
data_r_pq = tables_io.read("test_single_out.pq", keys=[''])
data_r_pq
data_r_h5 = tables_io.read("test_single_out.h5")
data_r_h5
data_native = tables_io.read("test_single_native.hf5")
data_native<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10071942446043165, 'fraction_numerical': 0.009592326139088728, 'mean_word_length': 5.434447300771208, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '2819', 'license': 'MIT', 'n_tokens_mistral': 888, 'n_tokens_neox': 872, 'n_words': 247, 'path': 'nb/singleTable_example.ipynb', 'repo_name': 'LSSTDESC/tables_io', 'size': '2502'}