Skip to content

BUG: bug in BlockManager._get_numeric_data, with invalid combine #6730

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
Mar 28, 2014
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
11 changes: 5 additions & 6 deletions pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
values = self.values if inplace else self.values.copy()
return [self.make_block(values.get_values(value), fill_value=value)]


def shift(self, periods, axis=0):
""" shift the block by periods """
N = len(self.values.T)
Expand Down Expand Up @@ -2674,18 +2674,17 @@ def get_data(self, copy=False, columns=None, **kwargs):
if len(blocks) == 0:
return self.make_empty()

return self.combine(blocks)
return self.combine(blocks, copy=copy)

def combine(self, blocks):
def combine(self, blocks, copy=True):
""" return a new manager with the blocks """
indexer = np.sort(np.concatenate([b.ref_locs for b in blocks]))
new_items = self.items.take(indexer)

new_blocks = []
for b in blocks:
b = b.copy(deep=False)
b.ref_items = new_items
new_blocks.append(b)
b = b.reindex_items_from(new_items, copy=copy)
new_blocks.extend(_valid_blocks(b))
new_axes = list(self.axes)
new_axes[0] = new_items
return self.__class__(new_blocks, new_axes, do_integrity_check=False)
Expand Down
14 changes: 12 additions & 2 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10424,6 +10424,16 @@ def test_get_numeric_data(self):
expected = df.ix[:, []]
assert_frame_equal(result, expected)

df = DataFrame.from_dict({'a':[1,2], 'b':['foo','bar'],'c':[np.pi,np.e]})
result = df._get_numeric_data()
expected = DataFrame.from_dict({'a':[1,2], 'c':[np.pi,np.e]})
assert_frame_equal(result, expected)

df = result.copy()
result = df._get_numeric_data()
expected = df
assert_frame_equal(result, expected)

def test_bool_describe_in_mixed_frame(self):
df = DataFrame({
'string_data': ['a', 'b', 'c', 'd', 'e'],
Expand Down Expand Up @@ -10937,7 +10947,7 @@ def test_rank2(self):
expected = DataFrame([[1.0, 3.0, 2.0], [1, 2, 3]]) / 3.0
result = df.rank(1, pct=True)
assert_frame_equal(result, expected)

df = DataFrame([[1, 3, 2], [1, 2, 3]])
expected = df.rank(0) / 2.0
result = df.rank(0, pct=True)
Expand All @@ -10950,7 +10960,7 @@ def test_rank2(self):
result = df.rank(1, numeric_only=False)
assert_frame_equal(result, expected)


expected = DataFrame([[2.0, 1.5, 1.0], [1, 1.5, 2]])
result = df.rank(0, numeric_only=False)
assert_frame_equal(result, expected)
Expand Down