Skip to content

Commit 05552d3

Browse files
[ArrayManager] Enable pytables IO by falling back to BlockManager (#41944)
1 parent 58a6bc1 commit 05552d3

18 files changed

+28
-45
lines changed

pandas/io/pytables.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@
8686
)
8787
from pandas.core.construction import extract_array
8888
from pandas.core.indexes.api import ensure_index
89-
from pandas.core.internals import BlockManager
89+
from pandas.core.internals import (
90+
ArrayManager,
91+
BlockManager,
92+
)
9093

9194
from pandas.io.common import stringify_path
9295
from pandas.io.formats.printing import (
@@ -3206,6 +3209,11 @@ def read(
32063209

32073210
def write(self, obj, **kwargs):
32083211
super().write(obj, **kwargs)
3212+
3213+
# TODO(ArrayManager) HDFStore relies on accessing the blocks
3214+
if isinstance(obj._mgr, ArrayManager):
3215+
obj = obj._as_manager("block")
3216+
32093217
data = obj._mgr
32103218
if not data.is_consolidated():
32113219
data = data.consolidate()
@@ -4015,6 +4023,10 @@ def _get_blocks_and_items(
40154023
):
40164024
# Helper to clarify non-state-altering parts of _create_axes
40174025

4026+
# TODO(ArrayManager) HDFStore relies on accessing the blocks
4027+
if isinstance(frame._mgr, ArrayManager):
4028+
frame = frame._as_manager("block")
4029+
40184030
def get_blk_items(mgr):
40194031
return [mgr.items.take(blk.mgr_locs) for blk in mgr.blocks]
40204032

pandas/tests/io/pytables/test_append.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
ensure_clean_store,
2626
)
2727

28-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
28+
pytestmark = pytest.mark.single
2929

3030

3131
@pytest.mark.filterwarnings("ignore:object name:tables.exceptions.NaturalNameWarning")
@@ -714,6 +714,10 @@ def check(obj, comparator):
714714
tm.assert_frame_equal(store.select("df2"), df)
715715

716716

717+
# TODO(ArrayManager) currently we rely on falling back to BlockManager, but
718+
# the conversion from AM->BM converts the invalid object dtype column into
719+
# a datetime64 column no longer raising an error
720+
@td.skip_array_manager_not_yet_implemented
717721
def test_append_raise(setup_path):
718722

719723
with ensure_clean_store(setup_path) as store:

pandas/tests/io/pytables/test_categorical.py

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
import pandas.util._test_decorators as td
5-
64
from pandas import (
75
Categorical,
86
DataFrame,
@@ -19,7 +17,6 @@
1917

2018
pytestmark = [
2119
pytest.mark.single,
22-
td.skip_array_manager_not_yet_implemented,
2320
# pytables https://github.com/PyTables/PyTables/issues/822
2421
pytest.mark.filterwarnings(
2522
"ignore:a closed node found in the registry:UserWarning"

pandas/tests/io/pytables/test_compat.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import pytest
22

3-
import pandas.util._test_decorators as td
4-
53
import pandas as pd
64
import pandas._testing as tm
75
from pandas.tests.io.pytables.common import ensure_clean_path
86

97
tables = pytest.importorskip("tables")
108

11-
pytestmark = td.skip_array_manager_not_yet_implemented
12-
139

1410
@pytest.fixture
1511
def pytables_hdf5_file():

pandas/tests/io/pytables/test_complex.py

-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import numpy as np
44
import pytest
55

6-
import pandas.util._test_decorators as td
7-
86
import pandas as pd
97
from pandas import (
108
DataFrame,
@@ -18,9 +16,6 @@
1816

1917
from pandas.io.pytables import read_hdf
2018

21-
# TODO(ArrayManager) HDFStore relies on accessing the blocks
22-
pytestmark = td.skip_array_manager_not_yet_implemented
23-
2419

2520
def test_complex_fixed(setup_path):
2621
df = DataFrame(

pandas/tests/io/pytables/test_errors.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import numpy as np
77
import pytest
88

9-
import pandas.util._test_decorators as td
10-
119
from pandas import (
1210
CategoricalIndex,
1311
DataFrame,
@@ -27,7 +25,7 @@
2725
_maybe_adjust_name,
2826
)
2927

30-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
28+
pytestmark = pytest.mark.single
3129

3230

3331
def test_pass_spec_to_storer(setup_path):

pandas/tests/io/pytables/test_file_handling.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
from pandas.compat import is_platform_little_endian
7-
import pandas.util._test_decorators as td
87

98
from pandas import (
109
DataFrame,
@@ -27,7 +26,7 @@
2726
Term,
2827
)
2928

30-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
29+
pytestmark = pytest.mark.single
3130

3231

3332
def test_mode(setup_path):

pandas/tests/io/pytables/test_keys.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
22

3-
import pandas.util._test_decorators as td
4-
53
from pandas import (
64
DataFrame,
75
HDFStore,
@@ -13,7 +11,7 @@
1311
tables,
1412
)
1513

16-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
14+
pytestmark = pytest.mark.single
1715

1816

1917
def test_keys(setup_path):

pandas/tests/io/pytables/test_put.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
from pandas.util import _test_decorators as td
3131

32-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
32+
pytestmark = pytest.mark.single
3333

3434

3535
def test_format_type(setup_path):

pandas/tests/io/pytables/test_pytables_missing.py

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import pandas as pd
66
import pandas._testing as tm
77

8-
pytestmark = td.skip_array_manager_not_yet_implemented
9-
108

119
@td.skip_if_installed("tables")
1210
def test_pytables_raises():

pandas/tests/io/pytables/test_read.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from pandas.io.pytables import TableIterator
2727

28-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
28+
pytestmark = pytest.mark.single
2929

3030

3131
def test_read_missing_key_close_store(setup_path):

pandas/tests/io/pytables/test_retain_attributes.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import pytest
44

55
from pandas._libs.tslibs import Timestamp
6-
import pandas.util._test_decorators as td
76

87
from pandas import (
98
DataFrame,
@@ -18,7 +17,7 @@
1817
ensure_clean_store,
1918
)
2019

21-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
20+
pytestmark = pytest.mark.single
2221

2322

2423
def test_retain_index_attributes(setup_path):

pandas/tests/io/pytables/test_round_trip.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
_default_compressor = "blosc"
3131

3232

33-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
33+
pytestmark = pytest.mark.single
3434

3535

3636
def test_conv_read_write(setup_path):

pandas/tests/io/pytables/test_select.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
from pandas._libs.tslibs import Timestamp
7-
import pandas.util._test_decorators as td
87

98
import pandas as pd
109
from pandas import (
@@ -28,7 +27,7 @@
2827

2928
from pandas.io.pytables import Term
3029

31-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
30+
pytestmark = pytest.mark.single
3231

3332

3433
def test_select_columns_in_where(setup_path):

pandas/tests/io/pytables/test_store.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import numpy as np
1111
import pytest
1212

13-
import pandas.util._test_decorators as td
14-
1513
import pandas as pd
1614
from pandas import (
1715
DataFrame,
@@ -42,8 +40,7 @@
4240
read_hdf,
4341
)
4442

45-
# TODO(ArrayManager) HDFStore relies on accessing the blocks
46-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
43+
pytestmark = pytest.mark.single
4744

4845

4946
def test_context(setup_path):

pandas/tests/io/pytables/test_subclass.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import numpy as np
22

3-
import pandas.util._test_decorators as td
4-
53
from pandas import (
64
DataFrame,
75
Series,
@@ -14,8 +12,6 @@
1412
read_hdf,
1513
)
1614

17-
pytestmark = td.skip_array_manager_not_yet_implemented
18-
1915

2016
class TestHDFStoreSubclass:
2117
# GH 33748

pandas/tests/io/pytables/test_time_series.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
import numpy as np
44
import pytest
55

6-
import pandas.util._test_decorators as td
7-
86
from pandas import (
97
DataFrame,
108
Series,
119
_testing as tm,
1210
)
1311
from pandas.tests.io.pytables.common import ensure_clean_store
1412

15-
pytestmark = [pytest.mark.single, td.skip_array_manager_not_yet_implemented]
13+
pytestmark = pytest.mark.single
1614

1715

1816
def test_store_datetime_fractional_secs(setup_path):

pandas/tests/io/pytables/test_timezones.py

-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
ensure_clean_store,
2525
)
2626

27-
# TODO(ArrayManager) HDFStore relies on accessing the blocks
28-
pytestmark = td.skip_array_manager_not_yet_implemented
29-
3027

3128
def _compare_with_tz(a, b):
3229
tm.assert_frame_equal(a, b)

0 commit comments

Comments
 (0)