Skip to content

Commit 6d49687

Browse files
committed
BUG: Series.align resets name when fill_value is specified
1 parent 921056d commit 6d49687

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

doc/source/whatsnew/v0.16.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Bug Fixes
308308
- Fixed latex output for multi-indexed dataframes (:issue:`9778`)
309309
- Bug causing an exception when setting an empty range using ``DataFrame.loc`` (:issue:`9596`)
310310

311-
311+
- Bug in ``Series.align`` resets ``name`` when ``fill_value`` is specified (:issue:`10067`)
312312

313313

314314
- Bug in hiding ticklabels with subplots and shared axes when adding a new plot to an existing grid of axes (:issue:`9158`)

pandas/core/generic.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -3406,6 +3406,9 @@ def _align_series(self, other, join='outer', axis=None, level=None,
34063406
else:
34073407
right_result = other.reindex(join_index, level=level)
34083408

3409+
left_result = left_result.__finalize__(self)
3410+
right_result = right_result.__finalize__(other)
3411+
34093412
# fill
34103413
fill_na = notnull(fill_value) or (method is not None)
34113414
if fill_na:
@@ -3414,8 +3417,7 @@ def _align_series(self, other, join='outer', axis=None, level=None,
34143417
right_result.fillna(fill_value, method=method,
34153418
limit=limit))
34163419
else:
3417-
return (left_result.__finalize__(self),
3418-
right_result.__finalize__(other))
3420+
return left_result, right_result
34193421

34203422
_shared_docs['where'] = ("""
34213423
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
@@ -5921,19 +5921,26 @@ def _check_align(a, b, how='left', fill=None):
59215921

59225922
assert_series_equal(aa, ea)
59235923
assert_series_equal(ab, eb)
5924+
self.assertEqual(aa.name, 'ts')
5925+
self.assertEqual(ea.name, 'ts')
5926+
self.assertEqual(ab.name, 'ts')
5927+
self.assertEqual(eb.name, 'ts')
59245928

59255929
for kind in JOIN_TYPES:
59265930
_check_align(self.ts[2:], self.ts[:-5], how=kind)
59275931
_check_align(self.ts[2:], self.ts[:-5], how=kind, fill=-1)
59285932

59295933
# empty left
59305934
_check_align(self.ts[:0], self.ts[:-5], how=kind)
5935+
_check_align(self.ts[:0], self.ts[:-5], how=kind, fill=-1)
59315936

59325937
# empty right
59335938
_check_align(self.ts[:-5], self.ts[:0], how=kind)
5939+
_check_align(self.ts[:-5], self.ts[:0], how=kind, fill=-1)
59345940

59355941
# both empty
59365942
_check_align(self.ts[:0], self.ts[:0], how=kind)
5943+
_check_align(self.ts[:0], self.ts[:0], how=kind, fill=-1)
59375944

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

0 commit comments

Comments
 (0)