Skip to content

Commit

Permalink
added votable.parquet test; other docstring fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
afaisst committed Sep 5, 2023
1 parent 8d0fdda commit 83afeb3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
14 changes: 6 additions & 8 deletions astropy/io/votable/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
'''
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions astropy/io/votable/tests/table_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
3 changes: 2 additions & 1 deletion astropy/io/votable/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,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

Check warning on line 3102 in astropy/io/votable/tree.py

View check run for this annotation

Codecov / codecov/patch

astropy/io/votable/tree.py#L3102

Added line #L3102 was not covered by tests
Expand Down

0 comments on commit 83afeb3

Please sign in to comment.