Skip to content

Commit

Permalink
BUG: Fix issue in preserving index name on empty DataFrame (#36532)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-Irv authored Sep 21, 2020
1 parent 84ac62f commit f59700b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Fixed regressions
- Fixed regression in :meth:`Series.__getitem__` incorrectly raising when the input was a frozenset (:issue:`35747`)
- Fixed regression in :meth:`read_excel` with ``engine="odf"`` caused ``UnboundLocalError`` in some cases where cells had nested child nodes (:issue:`36122`,:issue:`35802`)
- Fixed regression in :class:`DataFrame` and :class:`Series` comparisons between numeric arrays and strings (:issue:`35700`,:issue:`36377`)
- Fixed regression when setting empty :class:`DataFrame` column to a :class:`Series` in preserving name of index in frame (:issue:`36527`)

.. ---------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3190,7 +3190,8 @@ def _ensure_valid_index(self, value):

# GH31368 preserve name of index
index_copy = value.index.copy()
index_copy.name = self.index.name
if self.index.name is not None:
index_copy.name = self.index.name

self._mgr = self._mgr.reindex_axis(index_copy, axis=1, fill_value=np.nan)

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/indexing/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,11 @@ def test_index_name_empty(self):
)

tm.assert_frame_equal(df, expected)

# GH 36527
df = pd.DataFrame()
series = pd.Series(1.23, index=pd.RangeIndex(4, name="series_index"))
df["series"] = series
expected = pd.DataFrame(
{"series": [1.23] * 4}, index=pd.RangeIndex(4, name="series_index")
)

0 comments on commit f59700b

Please sign in to comment.