VOTable `columns=` in a different order from the file mixes up BINARY and BINARY2 columns · Issue #20512 · astropy/astropy · GitHub
Skip to content

VOTable columns= in a different order from the file mixes up BINARY and BINARY2 columns #20512

Open

Description

@jdavies-st

Description

While trying to fix #8946 with the Gaia VOTable BINARY2 input data described there, and only reading 2 columns, I discovered a bug, where if you give the column names out-of-order from which they appear in the file via columns=, then you get the data swapped between columns. It puts each column's values into another column.

Tables stored as TABLEDATA read correctly, so this is just problem with the BINARY and BINARY2 readers.

The example at the top of issue #8946, columns=['phot_g_mean_mag', 'parallax'], is affected - it returns the parallax values under phot_g_mean_mag, and vice-versa.

Expected behavior

Each column holds its own, correct values, whatever order columns lists them in.

How to Reproduce

from astropy.table import Table
from astropy.io.votable import parse_single_table

Table({"a": [1.0, 2.0], "b": [3.0, 4.0]}).write(
    "two_columns.vot", format="votable", tabledata_format="binary2", overwrite=True
)
print(parse_single_table("two_columns.vot", columns=["b", "a"]).to_table())

which swaps the values from b into a.

 a   b
--- ---
3.0 1.0
4.0 2.0

Column a should have 1.0 and 2.0, as it does with tabledata_format="tabledata". The result has the selected columns in file order, but the BINARY reader fills them in the order columns lists them.

Two related failures with BINARY and BINARY2:

  • If the columns have different dtypes, say string and float, you get ValueError: could not convert string to float: 'x'
  • And if you list a column twice (probably a mistake, but you never know) columns=["a", "a"], you get IndexError: list assignment index out of range. Should have a better error message.

This bug is in the released astropy 7.0 but not earlier.

Versions

platform
--------
platform.platform() = 'macOS-26.6.2-arm64-arm-64bit-Mach-O'
platform.version() = 'Darwin Kernel Version 25.6.0: Fri Jul 31 19:16:36 PDT 2026; root:xnu-12377.161.14~5/RELEASE_ARM64_T6030'
platform.python_version() = '3.14.7'

packages
--------
astropy              8.1.0.dev667+g89c450815
numpy                2.5.3
scipy                --
matplotlib           3.11.2
pandas               --
pyerfa               2.0.1.5

Activity

  1. jdavies-st commented on Oct 9, 2026

    @jdavies-st
    ContributorAuthor

    So listing the same column twice has always worked fine in astropy for TABLEDATA format. It has always returned the column once. It is only broke for BINARY and BINARY2 since astropy7.

    The following currently works:

    from astropy.table import Table
    from astropy.io.votable import parse_single_table
    
    Table({"a": [1.0, 2.0], "b": [3.0, 4.0]}).write(
        "test.vot", format="votable", tabledata_format="tabledata", overwrite=True
    )
    
    parsed = parse_single_table("test.vot", columns=["a", "a"])
    print(parsed)
    #  a 
    # ---
    # 1.0
    # 2.0

    And it is only table_format="binary" or table_format="binary2" where it currently raises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions