|
8 | 8 | import numpy as np
|
9 | 9 | import pytest
|
10 | 10 |
|
11 |
| -import pandas.util._test_decorators as td |
12 |
| - |
13 | 11 | import pandas as pd
|
14 | 12 | from pandas import (
|
15 | 13 | DataFrame,
|
@@ -43,40 +41,51 @@ def test_append_concat(self):
|
43 | 41 | assert isinstance(result.index, PeriodIndex)
|
44 | 42 | assert result.index[0] == s1.index[0]
|
45 | 43 |
|
46 |
| - # TODO(ArrayManager) using block internals to verify, needs rewrite |
47 |
| - @td.skip_array_manager_invalid_test |
48 |
| - def test_concat_copy(self): |
| 44 | + def test_concat_copy(self, using_array_manager): |
49 | 45 | df = DataFrame(np.random.randn(4, 3))
|
50 | 46 | df2 = DataFrame(np.random.randint(0, 10, size=4).reshape(4, 1))
|
51 | 47 | df3 = DataFrame({5: "foo"}, index=range(4))
|
52 | 48 |
|
53 | 49 | # These are actual copies.
|
54 | 50 | result = concat([df, df2, df3], axis=1, copy=True)
|
55 | 51 |
|
56 |
| - for b in result._mgr.blocks: |
57 |
| - assert b.values.base is None |
| 52 | + for arr in result._mgr.arrays: |
| 53 | + assert arr.base is None |
58 | 54 |
|
59 | 55 | # These are the same.
|
60 | 56 | result = concat([df, df2, df3], axis=1, copy=False)
|
61 | 57 |
|
62 |
| - for b in result._mgr.blocks: |
63 |
| - if b.dtype.kind == "f": |
64 |
| - assert b.values.base is df._mgr.blocks[0].values.base |
65 |
| - elif b.dtype.kind in ["i", "u"]: |
66 |
| - assert b.values.base is df2._mgr.blocks[0].values.base |
67 |
| - elif b.is_object: |
68 |
| - assert b.values.base is not None |
| 58 | + for arr in result._mgr.arrays: |
| 59 | + if arr.dtype.kind == "f": |
| 60 | + assert arr.base is df._mgr.arrays[0].base |
| 61 | + elif arr.dtype.kind in ["i", "u"]: |
| 62 | + assert arr.base is df2._mgr.arrays[0].base |
| 63 | + elif arr.dtype == object: |
| 64 | + if using_array_manager: |
| 65 | + # we get the same array object, which has no base |
| 66 | + assert arr is df3._mgr.arrays[0] |
| 67 | + else: |
| 68 | + assert arr.base is not None |
69 | 69 |
|
70 | 70 | # Float block was consolidated.
|
71 | 71 | df4 = DataFrame(np.random.randn(4, 1))
|
72 | 72 | result = concat([df, df2, df3, df4], axis=1, copy=False)
|
73 |
| - for b in result._mgr.blocks: |
74 |
| - if b.dtype.kind == "f": |
75 |
| - assert b.values.base is None |
76 |
| - elif b.dtype.kind in ["i", "u"]: |
77 |
| - assert b.values.base is df2._mgr.blocks[0].values.base |
78 |
| - elif b.is_object: |
79 |
| - assert b.values.base is not None |
| 73 | + for arr in result._mgr.arrays: |
| 74 | + if arr.dtype.kind == "f": |
| 75 | + if using_array_manager: |
| 76 | + # this is a view on some array in either df or df4 |
| 77 | + assert any( |
| 78 | + np.shares_memory(arr, other) |
| 79 | + for other in df._mgr.arrays + df4._mgr.arrays |
| 80 | + ) |
| 81 | + else: |
| 82 | + # the block was consolidated, so we got a copy anyway |
| 83 | + assert arr.base is None |
| 84 | + elif arr.dtype.kind in ["i", "u"]: |
| 85 | + assert arr.base is df2._mgr.arrays[0].base |
| 86 | + elif arr.dtype == object: |
| 87 | + # this is a view on df3 |
| 88 | + assert any(np.shares_memory(arr, other) for other in df3._mgr.arrays) |
80 | 89 |
|
81 | 90 | def test_concat_with_group_keys(self):
|
82 | 91 | # axis=0
|
|
0 commit comments