question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Saving a VOTable with an array of fixed size to a file only saves first element

See original GitHub issue

Description

I am trying to add metadata to a VOTable that I’m creating. This metadata corresponds to a tuple of known length. The data seems to be ok when inserted into the table but, when I save the table to a file, only the first element is saved.

Expected behavior

What I expect to see is the entire tuple saved in the file. The tuple is (1.0, 2.0, 3.0), what I see when I print params is [<PARAM ID="sampling" arraysize="3" datatype="double" name="sampling" value="(1.0, 2.0, 3.0)"/>]

Actual behavior

Only the first element is saved in the file. When I open it, I see: PARAM section I see: <PARAM ID="sampling" arraysize="3" datatype="double" name="sampling" value="1"/>

Steps to Reproduce

What I’m doing to create the table and add the metadata is the following:

# Create a new VOTable file
votable = VOTableFile()
# Add a resource
resource = Resource(); votable.resources.append(resource)
# Add a table for the spectra (and add the sampling as metadata)
spectra_table = Table(votable); resource.tables.append(spectra_table)
# Add sampling as param
sampling = tuple([1.0, 2.0, 3.0])
# I'm using a list because, later, I could have more than one param
params = [Param(votable, name='sampling', datatype='double', arraysize='3', value=sampling)]
spectra_table.params.extend(params)

When I print params, I see [<PARAM ID="sampling" arraysize="3" datatype="double" name="sampling" value="(1.0, 2.0, 3.0)"/>] which seems to be ok. However, when I save this to a file:

votable.to_xml('table_with_params.xml')

In the PARAM section I see: <PARAM ID="sampling" arraysize="3" datatype="double" name="sampling" value="1"/>.

I tried sampling being a tuple, list and numpy array, but they all lead to the same result. If I use * instead of the fixed known length, the entire array is saved.

System Details

Linux-5.4.0-52-generic-x86_64-with-glibc2.29 Python 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0] Numpy 1.18.2 astropy 4.3.dev268+g883a7c4f5 Scipy 1.4.1 Matplotlib 3.2.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pllimcommented, Jan 28, 2021

Hello. I don’t think it is released yet, so you will have to use the dev version for now. Since #11157 was milestoned for 4.0.5, if there is an urgent need, we can try for a release soon; otherwise, it is more likely to happen when 4.3 comes out.

0reactions
druzmierescommented, Jan 28, 2021

Hi, in which version of astropy is this patch included? I’d like to try it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

VOTable XML Handling (astropy.io.votable) — Astropy v5.2
VOTable files are made up of nested RESOURCE elements, each of which may contain one ... If the field is a fixed-size array,...
Read more >
VOTable XML handling (astropy.io.votable) — Astropy v1.0.4
This data is a Numpy record array. The columns get their names from both the ID and name attributes of the FIELD elements...
Read more >
Expanding a bash array only gives the first element
Try echo $files , it will only print the first element of the array. The for loop prints only one element for the...
Read more >
Introduction to vo.table - stsdas
VOTable files are made up of nested RESOURCE elements, each of which may contain one or more TABLE elements. The TABLE elements contain...
Read more >
The GAVO VOTable Library - VO related docs
votable.load only looks at the first TABLE element encountered. ... result using votable.save(data, metadata, destF), where destF is a writable file object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found