Skip to content

Commit 2709f77

Browse files
committed
Merge pull request pandas-dev#10067 from sinhrks/align_name
BUG: Series.align resets name when fill_value is specified
2 parents 753d66b + 186b20d commit 2709f77

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

doc/source/whatsnew/v0.17.0.txt

+4
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ Bug Fixes
7979

8080

8181
- Bug in `Series.plot(label="LABEL")` not correctly setting the label (:issue:`10119`)
82+
8283
- Bug in `plot` not defaulting to matplotlib `axes.grid` setting (:issue:`9792`)
8384

85+
- Bug in ``Series.align`` resets ``name`` when ``fill_value`` is specified (:issue:`10067`)
86+
87+
8488

8589
- Bug in GroupBy.get_group raises ValueError when group key contains NaT (:issue:`6992`)
8690

pandas/core/generic.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -3365,11 +3365,10 @@ def _align_series(self, other, join='outer', axis=None, level=None,
33653365
level=level,
33663366
return_indexers=True)
33673367

3368-
left_result = self._reindex_indexer(join_index, lidx, copy)
3369-
right_result = other._reindex_indexer(join_index, ridx, copy)
3368+
left = self._reindex_indexer(join_index, lidx, copy)
3369+
right = other._reindex_indexer(join_index, ridx, copy)
33703370

33713371
else:
3372-
33733372
# one has > 1 ndim
33743373
fdata = self._data
33753374
if axis == 0:
@@ -3399,23 +3398,19 @@ def _align_series(self, other, join='outer', axis=None, level=None,
33993398
if copy and fdata is self._data:
34003399
fdata = fdata.copy()
34013400

3402-
left_result = DataFrame(fdata)
3401+
left = DataFrame(fdata)
34033402

34043403
if ridx is None:
3405-
right_result = other
3404+
right = other
34063405
else:
3407-
right_result = other.reindex(join_index, level=level)
3406+
right = other.reindex(join_index, level=level)
34083407

34093408
# fill
34103409
fill_na = notnull(fill_value) or (method is not None)
34113410
if fill_na:
3412-
return (left_result.fillna(fill_value, method=method, limit=limit,
3413-
axis=fill_axis),
3414-
right_result.fillna(fill_value, method=method,
3415-
limit=limit))
3416-
else:
3417-
return (left_result.__finalize__(self),
3418-
right_result.__finalize__(other))
3411+
left = left.fillna(fill_value, method=method, limit=limit, axis=fill_axis)
3412+
right = right.fillna(fill_value, method=method, limit=limit)
3413+
return (left.__finalize__(self), right.__finalize__(other))
34193414

34203415
_shared_docs['where'] = ("""
34213416
Return an object of same shape as self and whose corresponding

pandas/tests/test_series.py

+7
Original file line numberDiff line numberDiff line change
@@ -5932,19 +5932,26 @@ def _check_align(a, b, how='left', fill=None):
59325932

59335933
assert_series_equal(aa, ea)
59345934
assert_series_equal(ab, eb)
5935+
self.assertEqual(aa.name, 'ts')
5936+
self.assertEqual(ea.name, 'ts')
5937+
self.assertEqual(ab.name, 'ts')
5938+
self.assertEqual(eb.name, 'ts')
59355939

59365940
for kind in JOIN_TYPES:
59375941
_check_align(self.ts[2:], self.ts[:-5], how=kind)
59385942
_check_align(self.ts[2:], self.ts[:-5], how=kind, fill=-1)
59395943

59405944
# empty left
59415945
_check_align(self.ts[:0], self.ts[:-5], how=kind)
5946+
_check_align(self.ts[:0], self.ts[:-5], how=kind, fill=-1)
59425947

59435948
# empty right
59445949
_check_align(self.ts[:-5], self.ts[:0], how=kind)
5950+
_check_align(self.ts[:-5], self.ts[:0], how=kind, fill=-1)
59455951

59465952
# both empty
59475953
_check_align(self.ts[:0], self.ts[:0], how=kind)
5954+
_check_align(self.ts[:0], self.ts[:0], how=kind, fill=-1)
59485955

59495956
def test_align_fill_method(self):
59505957
def _check_align(a, b, how='left', method='pad', limit=None):

0 commit comments

Comments
 (0)