Skip to content

BUG: Series.align resets name when fill_value is specified #10067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/source/whatsnew/v0.17.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,14 @@ Bug Fixes
- Bug in display datetimes with mixed frequencies uniformly; display 'ms' datetimes to the proper precision. (:issue:`10170`)



- Bug in ``DatetimeIndex`` and ``TimedeltaIndex`` names are lost after timedelta arithmetics ( :issue:`9926`)

- Bug in `Series.plot(label="LABEL")` not correctly setting the label (:issue:`10119`)

- Bug in `plot` not defaulting to matplotlib `axes.grid` setting (:issue:`9792`)

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



21 changes: 8 additions & 13 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3365,11 +3365,10 @@ def _align_series(self, other, join='outer', axis=None, level=None,
level=level,
return_indexers=True)

left_result = self._reindex_indexer(join_index, lidx, copy)
right_result = other._reindex_indexer(join_index, ridx, copy)
left = self._reindex_indexer(join_index, lidx, copy)
right = other._reindex_indexer(join_index, ridx, copy)

else:

# one has > 1 ndim
fdata = self._data
if axis == 0:
Expand Down Expand Up @@ -3399,23 +3398,19 @@ def _align_series(self, other, join='outer', axis=None, level=None,
if copy and fdata is self._data:
fdata = fdata.copy()

left_result = DataFrame(fdata)
left = DataFrame(fdata)

if ridx is None:
right_result = other
right = other
else:
right_result = other.reindex(join_index, level=level)
right = other.reindex(join_index, level=level)

# fill
fill_na = notnull(fill_value) or (method is not None)
if fill_na:
return (left_result.fillna(fill_value, method=method, limit=limit,
axis=fill_axis),
right_result.fillna(fill_value, method=method,
limit=limit))
else:
return (left_result.__finalize__(self),
right_result.__finalize__(other))
left = left.fillna(fill_value, method=method, limit=limit, axis=fill_axis)
right = right.fillna(fill_value, method=method, limit=limit)
return (left.__finalize__(self), right.__finalize__(other))

_shared_docs['where'] = ("""
Return an object of same shape as self and whose corresponding
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -5932,19 +5932,26 @@ def _check_align(a, b, how='left', fill=None):

assert_series_equal(aa, ea)
assert_series_equal(ab, eb)
self.assertEqual(aa.name, 'ts')
self.assertEqual(ea.name, 'ts')
self.assertEqual(ab.name, 'ts')
self.assertEqual(eb.name, 'ts')

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

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

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

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

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