From 952a3f4da0e1134d9e4341020a3482df1813d308 Mon Sep 17 00:00:00 2001 From: Andreas Faisst Date: Tue, 5 Sep 2023 16:27:09 -0700 Subject: [PATCH] added votable.parquet test; other docstring fixes --- astropy/io/votable/connect.py | 14 ++++----- astropy/io/votable/tests/test_table.py | 39 ++++++++++++++++++++++++++ astropy/io/votable/tree.py | 3 +- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/astropy/io/votable/connect.py b/astropy/io/votable/connect.py index acf0bd620d6b..c24183522f1c 100644 --- a/astropy/io/votable/connect.py +++ b/astropy/io/votable/connect.py @@ -184,7 +184,6 @@ def write_table_votable( # VOTable with embedded/linked Parquet file # -# added by ALF - Sept 5 2023 def write_table_votable_parquet(tab, filename, column_metadata, overwrite): ''' @@ -202,18 +201,17 @@ def write_table_votable_parquet(tab, filename, column_metadata, overwrite): Parameters ----------- - tab: astropy table + tab : astropy table Contains the data - filename: str + filename : str The file name of the VOTable (e.g., "test.vot"). IMPORTANT: Needs to be a full path (i.e. no "../" or "./") - column_metadata: dictionary + column_metadata : dictionary Contains the metadata for the columns such as "unit" or "ucd" or "utype". - Example: - column_metadata = {"id":{"unit":"","ucd":"meta.id","utype":"none"}, - "mass":{"unit":"solMass","ucd":"phys.mass","utype":"none"} } - overwrite: bool + (Example: column_metadata = {"id":{"unit":"","ucd":"meta.id","utype":"none"}, + "mass":{"unit":"solMass","ucd":"phys.mass","utype":"none"} } ) + overwrite : bool Set to True to enable overwriting. Returns diff --git a/astropy/io/votable/tests/test_table.py b/astropy/io/votable/tests/test_table.py index e67efc489bd3..e024c24e58a2 100644 --- a/astropy/io/votable/tests/test_table.py +++ b/astropy/io/votable/tests/test_table.py @@ -52,6 +52,45 @@ def home_is_tmpdir(monkeypatch, tmp_path): monkeypatch.setenv("USERPROFILE", str(tmp_path)) +def test_read_write_votable_parquet(tmp_path): + """ + Test to write VOTable with Parquet serialization + """ + + # Create some fake data + number_of_objects = 10 + ids = ["COSMOS_{:03g}".format(ii) for ii in range(number_of_objects)] + redshift = np.random.uniform(low=0, high=3, size=number_of_objects) + mass = np.random.uniform(low=1e8, high=1e10, size=number_of_objects) + sfr = np.random.uniform(low=1, high=100, size=number_of_objects) + astropytab = Table([ids, redshift, mass, sfr], names=["id","z","mass","sfr"]) + + # Create Column metadata + column_metadata = {"id":{"unit":"","ucd":"meta.id","utype":"none"}, + "z":{"unit":"","ucd":"src.redshift","utype":"none"}, + "mass":{"unit":"solMass","ucd":"phys.mass","utype":"none"}, + "sfr":{"unit":"solMass yr-1","ucd":"phys.SFR","utype":"none"} + } + + # Write VOTable with Parquet serialization + filename = os.path.join(tmp_path, "test_votable_parquet.vot") + astropytab.write(filename=filename, column_metadata=column_metadata, + overwrite=True, format="votable.parquet") + + # Open created VOTable with Parquet serialization + votable = parse(filename) + + # Get table out + votable_table = votable.resources[0].tables[0].array + + # compare + if (astropytab == votable_table).all(): + print("Test Success") + else: + print("Test failed") + + + def test_table(tmp_path): # Read the VOTABLE with np.errstate(over="ignore"): diff --git a/astropy/io/votable/tree.py b/astropy/io/votable/tree.py index 259d0c7fc666..0a67f1dbaebc 100644 --- a/astropy/io/votable/tree.py +++ b/astropy/io/votable/tree.py @@ -3094,7 +3094,8 @@ def _parse_fits(self, iterator, extnum, config): def _parse_parquet(self, iterator, config): ''' - Added by A. Faisst Jul/28/2023 + Functionality to parse parquet files that are embedded + in VOTables. ''' # looks like votable already has a "Table" imported. from astropy.table import Table as Table2