Repository navigation
Add function to flatten N-d columns to multiple 1-d columns - #20138
Merged
Merged
Conversation
Contributor
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
This was referenced Jul 28, 2026
mhvk
approved these changes
Jul 31, 2026
mhvk
left a comment
Contributor
There was a problem hiding this comment.
I think this is a good idea, and the implementation is nice. For later, I wonder if we shouldn't expose the opposite direction too?
| out = represent_nd_columns_as_1d_columns(tbl) | ||
| # Original 1-D column is preserved unchanged | ||
| assert "a.0" in out.colnames | ||
| np.testing.assert_array_equal(out["a.0"], [10, 20, 30]) |
Contributor
There was a problem hiding this comment.
Isn't this stronger, out["a.0"] is tbl["a.0"]? (fine to keep test as is, though)
Member
Author
There was a problem hiding this comment.
Since it is a new table, the column object is new so that test fails. However, the data are shared since the new table is made with copy=False, so I added a test for that.
taldcroft
force-pushed
the
table-flatten-to-1d-columns
branch
from
July 31, 2026 10:19
7e8a4df to
167626f
Compare
taldcroft
enabled auto-merge (squash)
July 31, 2026 10:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request is to add a new table function
represent_nd_columns_as_1d_columnsthat flattens any N-Dcolumns into multiple 1-D
~astropy.table.Columnor~astropy.table.MaskedColumncolumns and returns a new table. This can be useful for writing tables to file formats that do not support N-D
columns or converting to a data frame.
In the original discussion in #11148 the idea was a new
TablemethodTable.flatten()that flattens both mixins and N-d columns. This PR takes a more granular approach and makes a new analog oftable.serialize.represent_mixins_as_columns. The new functiontable.serialize.represent_nd_columns_as_1d_columnsis exposed in thetablepackage API.I'm not sure we need a new
Table.flatten()method, but that is for discussion. This method would basically just call the represent N-d function and then the represent mixins function and return the result.Fixes #11148
AI disclosure
I used GitHub Copilot for these bits:
table/__init__.pyI have reviewed all the content carefully.