Skip to content

Commit 4e58cf4

Browse files
taldcrofteteq
authored andcommitted
Merge pull request #11921 from taldcroft/table-pandas-1.3-index-name
Fix problem in to_pandas() introduced in pandas 1.3.0
1 parent 3aaad22 commit 4e58cf4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

astropy/table/table.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,13 @@ def _encode_mixins(tbl):
36823682
if isinstance(v, Series):
36833683
v.index = idx
36843684

3685-
return DataFrame(out, **kwargs)
3685+
df = DataFrame(out, **kwargs)
3686+
if index:
3687+
# Explicitly set the pandas DataFrame index to the original table
3688+
# index name.
3689+
df.index.name = idx.info.name
3690+
3691+
return df
36863692

36873693
@classmethod
36883694
def from_pandas(cls, dataframe, index=False, units=None):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fix an issue in ``Table.to_pandas(index=<colname>)`` where the index column name
2+
was not being set properly for the ``DataFrame`` index. This was introduced by
3+
an API change in pandas version 1.3.0. Previously when creating a ``DataFrame``
4+
with the index set to an astropy ``Column``, the ``DataFrame`` index name was
5+
automatically set to the column name.

0 commit comments

Comments
 (0)