Repository navigation
Conversation
|
|
mhvk
left a comment
There was a problem hiding this comment.
Just a quick flyby of the draft: I like the approach! So far only a comment about a mistake in the comments...
Also add FLATTEN_MULTIDIM constant. This specifies the context types for which multidimensional data will be flattened to a list of 1-d arrays.
4b8c811 to
2710bd3
Compare
|
@mhvk - I rebased this and did a bit of touchup. I think this is ready for review now. |
| astropy.time | ||
| ^^^^^^^^^^^^ | ||
|
|
||
| - Add new time format ``unix_ptp`` (Precision Time Protocol) which provides |
There was a problem hiding this comment.
Oops, something went wrong in the rebase. Will fix.
| import pytest | ||
| import numpy as np | ||
|
|
||
| from astropy.table import Table, Column, QTable, NdarrayMixin |
There was a problem hiding this comment.
In this file I refactored the serialization testing out to a new table module test_serialize. The goal is to unify such testing for FITS, HDF5 and ECSV. However this proved a little tricky on my first attempt so the refactor only currently applies to ECSV. In the context of this PR that should be OK?
| """ | ||
| t = Table([np.arange(4).reshape(2, 2), [1, 2]], names=['a', 'b']) | ||
| t = Table() | ||
| t['a'] = np.arange(24).reshape(2, 3, 4) |
There was a problem hiding this comment.
Basic testing here, more comprehensive in test_serialize.py.
| (for N > 1) by optionally turning it into the required number of 1-d | ||
| arrays (e.g. for ECSV or None context). | ||
|
|
||
| For instance a Column with shape (2, 2, 20) will turn into four columns |
There was a problem hiding this comment.
Will fix the (2, 2, 20) here.
| ndarrays within a Table. This is a subclass of numpy.ndarray | ||
| and has the same initialization options as ndarray(). | ||
| """ | ||
| __module__ = 'astropy.table.table' |
There was a problem hiding this comment.
This class definition is the same as the original that was taken out of table.py, with the exception of this line and the one below. I don't remember precisely what hacking the __module__ here was doing, but it might have been for the docs.
|
|
||
| # Context types for which multidimensional data will be flattened to | ||
| # a list of 1-d arrays. | ||
| FLATTEN_MULTIDIM = ['ecsv'] |
There was a problem hiding this comment.
Not clear if there will ever be another context that supports N-d serialization by flattening, but this seemed better than hardwiring 'ecsv' in the code.
|
|
||
| Creating a table with a `~astropy.coordinates.SkyCoord` column can be accomplished with a mixin | ||
| column, which is supported by `ECSV <https://docs.astropy.org/en/stable/api/astropy.io.ascii.Ecsv.html>`_. To store a mixin column:: | ||
| Creating a table with a `~astropy.coordinates.SkyCoord` column can be |
There was a problem hiding this comment.
Just a reformat for column width.
| if not has_info_class(data, MixinInfo): | ||
| col_cls = MaskedColumn if (hasattr(data, 'mask') | ||
| and np.any(data.mask)) else Column | ||
| # TODO: I think the **info here is not really needed and tests pass |
There was a problem hiding this comment.
Nominally planning to leave this TODO for another time since the impact is trickier to understand.
| else: | ||
| new_name = name + '.' + data_attr | ||
|
|
||
| # If the data attribute is not a Mixin (aka a Column or ndarray) and |
There was a problem hiding this comment.
This is the core inner change that makes it all work.
| class NdarrayMixinInfo(ParentDtypeInfo): | ||
| _represent_as_dict_primary_data = 'data' | ||
|
|
||
| def _represent_as_dict(self): |
|
Parenthetical to astropy/astropy-APEs#64, I see the section below this change which discusses multidimensional columns. With this PR it might be possible to make that scheme part of the standard, though it does rely on a special column naming convention. This is unique if the serialized metadata are parsed, but that is outside of the standard currently. |
|
Closing in favor of ideas mentioned in #11368 |
Description
This pull request is to support reading and writing multidimensional columns in ECSV format.
This also does consistent checking of table column dimensions for all built-in ASCII formats and raises a useful error message for multidimensional columns for formats that cannot support it.
For instance the following will round-trip and give back the same N-d column.
Fixes #11148