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.

io.ascii basic and fixed_width formats do not round-trip boolean data

See original GitHub issue

Description

When reading back an astropy table that had been written in fixed_width_two_line format and had contained a boolian column, the boolean values get read back as a string

Expected behavior

I expected to get the table back in the formats in which it was writen

Actual behavior

As noted, I got back a string value for True or False, and so I could not run the same code on the table that I could run before it was written out.

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on…]
from astropy.table import Table
import numpy as np

z=np.linspace(0,50)
x=Table([z,z],names=['foo','goo'])
x['Good']=True
x.info()
x.write('foo.txt',format='ascii.fixed_width_two_line',overwrite=True)
xx=ascii.read('foo.txt')
xx.info()
        

Here is what this produces

from astropy.table import Table

import numpy as np

​

z=np.linspace(0,50)

x=Table([z,z],names=['foo','goo'])

x['Good']=True

x.info()

x.write('foo.txt',format='ascii.fixed_width_two_line',overwrite=True)

xx=ascii.read('foo.txt')

xx.info()

        

<Table length=50>
name  dtype 
---- -------
 foo float64
 goo float64
Good    bool
<Table length=50>
name  dtype 
---- -------
 foo float64
 goo float64
Good    str4

System Details

import platform; print(platform.platform()) Darwin-19.6.0-x86_64-i386-64bit import sys; print(“Python”, sys.version) Python 3.7.11 (default, Jul 27 2021, 07:03:16) [Clang 10.0.0 ] import erfa; print(“pyerfa”, erfa.version) pyerfa 1.7.1.1 import astropy; print(“astropy”, astropy.version) astropy 4.2 import scipy; print(“Scipy”, scipy.version) Scipy 1.4.1 import matplotlib; print(“Matplotlib”, matplotlib.version) Matplotlib 3.5.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
taldcroftcommented, Apr 5, 2022

These days I’m less and less inclined to have configuration options that silently change the behavior of code. In other words when a line of code or function behaves fundamentally differently based on a config item, then that makes it hard for readers of the code to know what it will do.

Instead, even if it is a little less convenient, it is better to be explicit.

1reaction
pllimcommented, Feb 7, 2022

Oh, wait… maybe I typed it wrong. Seems to work now!

from astropy.table import Table
import numpy as np

z=np.linspace(0,50)
x=Table([z,z],names=['foo','goo'])
x['Good']=True
x.write('foo.txt',format='ascii.ecsv',overwrite=True)
xx=Table.read('foo.txt', format='ascii.ecsv')
xx.info()
<Table length=50>
name  dtype 
---- -------
 foo float64
 goo float64
Good    bool
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unified File Read/Write Interface — Astropy v5.2
For writing and reading tables to ASCII in a way that fully reproduces the table data, types, and metadata (i.e., the table will...
Read more >
IO tools (text, CSV, HDF5, …) — pandas 1.5.2 documentation
Specifying column data types#. You can indicate the data type for the whole DataFrame or individual columns: >>>
Read more >
astropy/CHANGES.rst at main - GitHub
Now this raises an exception because the string is not in ISO format. ... each data type as the tuple returned by the...
Read more >
asciitable 0.8.0 documentation
An extensible ASCII table reader and writer for Python 2 and 3. Asciitable can read and write a wide range of ASCII table...
Read more >
Data Format Description Language (DFDL) v1.0 Specification
An XML schema is written for the logical model of the data. The schema is augmented with special DFDL annotations. These annotations are...
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