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.

ResourceWarning when reading ascii tables

See original GitHub issue

Using an example ecsv file from the astropy documentation:

# %ECSV 0.9
# ---
# datatype:
# - {name: a, unit: m / s, datatype: int64, format: '%03d'}
# - {name: b, unit: km, datatype: int64, description: This is column b}
a b
001 2
004 3

(although this works for anything I tried, including rdb files) when I try to read it with a python with warnings enabled (e.g. python -Wd) I get a resource warning:

>>> Table.read("test.ecsv")
/Users/timj/work/lsstsw3/miniconda/envs/lsst-scipipe/lib/python3.7/site-packages/astropy/io/ascii/connect.py:37: ResourceWarning: unclosed file <_io.TextIOWrapper name='test.ecsv' encoding='UTF-8'>
  return read(filename, format=format, **kwargs)
<Table length=2>
  a     b  
m / s   km 
int64 int64
----- -----
  001     2
  004     3

Specifying the format on the read does not trigger a warning:

>>> Table.read("test.ecsv", format="ascii.ecsv")
<Table length=2>
  a     b  
m / s   km 
int64 int64
----- -----
  001     2
  004     3

and neither does using astropy.io.ascii.read directly. So far “ascii.rdb” also behaves like this but “ascii.latex” does not.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
timjcommented, May 7, 2019

Fast reader does not seem to be the issue:

>>> t = Table.read("test.ecsv", fast_reader=False)
/Users/timj/work/lsstsw3/miniconda/envs/lsst-scipipe/lib/python3.7/site-packages/astropy/io/ascii/connect.py:37: ResourceWarning: unclosed file <_io.TextIOWrapper name='test.ecsv' encoding='UTF-8'>
  return read(filename, format=format, **kwargs)
0reactions
bnavigatorcommented, Oct 22, 2020

These messages still appear when testing 4.1:

[  359s] io/ascii/tests/test_connect.py::test_read_csv
[  359s]   /usr/lib/python3.8/site-packages/astropy/io/ascii/connect.py:18: ResourceWarning: unclosed file <_io.TextIOWrapper name='/usr/lib/python3.8/site-packages/astropy/io/ascii/tests/data/simple_csv.csv' encoding='UTF-8'>
[  359s]     return read(filename, **kwargs)
[  359s] 
[  359s] io/ascii/tests/test_connect.py::test_auto_identify_ecsv
[  359s]   /usr/lib/python3.8/site-packages/astropy/io/ascii/connect.py:18: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/pytest-of-abuild/pytest-0/popen-gw0/test_auto_identify_ecsv0/tmpFile.ecsv' encoding='UTF-8'>
[  359s]     return read(filename, **kwargs)
[  359s] 
[  359s] io/ascii/tests/test_ecsv.py::test_round_trip_masked_table_default
[  359s]   /usr/lib/python3.8/site-packages/astropy/io/ascii/connect.py:18: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/pytest-of-abuild/pytest-0/popen-gw0/test_round_trip_masked_table_d0/test.ecsv' encoding='UTF-8'>
[  359s]     return read(filename, **kwargs)

And more of the same type for many different file type tests.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASCII Tables (astropy.io.ascii) — Astropy v5.2
astropy.io.ascii provides methods for reading and writing a wide range of ASCII data table formats via built-in Extension Reader Classes.
Read more >
Reading and Writing tabular ASCII data
Astronomers love storing tabular data in human-readable ASCII tables. ... One of these is the file() object which can be used to read...
Read more >
The Python Standard Library — Python 3.11.1 documentation
Python's standard library is very extensive, offering a wide range of facilities as indicated by the long table of contents listed below.
Read more >
Reading an "ascii" table that is unicode · Issue #3826 - GitHub
The ESO archive contains some tables that include unicode characters, e.g. csv tables. For example, here's one in raw form: 'Release Date ...
Read more >
Python ASCII Reading tables - Stack Overflow
What I did. I separated columns and added to different lists. Now I have got access for different columns:
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