Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying a list of column units to io.ascii.read() #9639

Closed
adrn opened this issue Nov 20, 2019 · 5 comments · Fixed by #9671
Closed

Allow specifying a list of column units to io.ascii.read() #9639

adrn opened this issue Nov 20, 2019 · 5 comments · Fixed by #9671

Comments

@adrn
Copy link
Member

adrn commented Nov 20, 2019

I'm using io.ascii.read to read in a text table that has no column names or units, but I want to (ideally) get back a QTable with column names and units that I specify. I know I can use names=[...] to set the column names, but it would be nice if there was an equivalent for units as well. For example, if I have an ascii table that looks like this:

-37.417 0.011
34.846 0.010
42.567 0.010

in some file, it would be nice if I could do something like:

ascii.read(filename, names=['a', 'b'], units=[u.one, u.kpc], cls=QTable)

Apologies if this functionality already exists! I couldn't find this in the io.ascii docs.

@adrn
Copy link
Member Author

adrn commented Nov 20, 2019

Oh, and for completeness, my workaround is to do:

tbl = ascii.read(filename, names=['a', 'b'])
tbl['a'].unit = u.one
tbl['b'].unit = u.km/u.s
tbl = QTable(tbl)

@mhvk
Copy link
Contributor

mhvk commented Nov 21, 2019

If we go this route, possibly handier might be to just have Table.__init__ handle units (but then maybe also other attributes?). Though perhaps it is easier to allow one to provide some of the information that would be taken from a header (maybe even as additional "header lines").

@taldcroft
Copy link
Member

taldcroft commented Nov 25, 2019

@adrn - about the workaround, QTable will automatically upgrade a Column to Quantity if you add units, so below works. (I'm not sure if this little feature is documented though...):

tbl = QTable.read(filename)
tbl['a'].unit = u.one
tbl['b'].unit = u.km/u.s

But I agree with @mhvk it could be useful to allow a units specifier to Table that could take either a sequence that maps to the columns (where None is used for columns with no unit) or a dict. I think this would essentially be the last step in table initialization. I guess while we're at it we need to complete the set and add descriptions as an init kwarg so all the column metadata is specifiable.

That takes this out of the realm of io.ascii and could apply to every unified reader at once. [EDIT], assuming we add units and descriptions to the Table.read connector.

This should be an easy PR. 4.0?? 😈

@pllim
Copy link
Member

pllim commented Nov 25, 2019

IMHO it's a little too late for 4.0 now. And since this is a new feature, how about 4.1?

@taldcroft taldcroft added this to the v4.1 milestone Nov 25, 2019
@taldcroft
Copy link
Member

Fair enough, can't hurt to ask!

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

Successfully merging a pull request may close this issue.

4 participants