Skip to content

Commit 6088f4c

Browse files
committed
TST: move to test_subclass.py
1 parent 68b5e69 commit 6088f4c

File tree

2 files changed

+54
-44
lines changed

2 files changed

+54
-44
lines changed

pandas/tests/io/pytables/test_store.py

-44
Original file line numberDiff line numberDiff line change
@@ -4888,50 +4888,6 @@ def test_unsuppored_hdf_file_error(self, datapath):
48884888
with pytest.raises(ValueError, match=message):
48894889
pd.read_hdf(data_path)
48904890

4891-
def test_supported_for_subclasses_dataframe(self):
4892-
class SubDataFrame(DataFrame):
4893-
@property
4894-
def _constructor(self):
4895-
return SubDataFrame
4896-
4897-
data = {"a": [1, 2], "b": [3, 4]}
4898-
sdf = SubDataFrame(data, dtype=np.intp)
4899-
4900-
expected = DataFrame(data, dtype=np.intp)
4901-
4902-
with ensure_clean_path("temp.h5") as path:
4903-
sdf.to_hdf(path, "df")
4904-
result = read_hdf(path, "df")
4905-
tm.assert_frame_equal(result, expected)
4906-
4907-
with ensure_clean_path("temp.h5") as path:
4908-
with HDFStore(path) as store:
4909-
store.put("df", sdf)
4910-
result = read_hdf(path, "df")
4911-
tm.assert_frame_equal(result, expected)
4912-
4913-
def test_supported_for_subclasses_series(self):
4914-
class SubSeries(Series):
4915-
@property
4916-
def _constructor(self):
4917-
return SubSeries
4918-
4919-
data = [1, 2, 3]
4920-
sser = SubSeries(data, dtype=np.intp)
4921-
4922-
expected = Series(data, dtype=np.intp)
4923-
4924-
with ensure_clean_path("temp.h5") as path:
4925-
sser.to_hdf(path, "ser")
4926-
result = read_hdf(path, "ser")
4927-
tm.assert_series_equal(result, expected)
4928-
4929-
with ensure_clean_path("temp.h5") as path:
4930-
with HDFStore(path) as store:
4931-
store.put("ser", sser)
4932-
result = read_hdf(path, "ser")
4933-
tm.assert_series_equal(result, expected)
4934-
49354891

49364892
@pytest.mark.parametrize("bad_version", [(1, 2), (1,), [], "12", "123"])
49374893
def test_maybe_adjust_name_bad_version_raises(bad_version):
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import numpy as np
2+
3+
from pandas import DataFrame, Series
4+
import pandas._testing as tm
5+
from pandas.tests.io.pytables.common import ensure_clean_path
6+
7+
from pandas.io.pytables import HDFStore, read_hdf
8+
9+
10+
class TestHDFStoreSubclass:
11+
# GH 33748
12+
def test_supported_for_subclass_dataframe(self):
13+
class SubDataFrame(DataFrame):
14+
@property
15+
def _constructor(self):
16+
return SubDataFrame
17+
18+
data = {"a": [1, 2], "b": [3, 4]}
19+
sdf = SubDataFrame(data, dtype=np.intp)
20+
21+
expected = DataFrame(data, dtype=np.intp)
22+
23+
with ensure_clean_path("temp.h5") as path:
24+
sdf.to_hdf(path, "df")
25+
result = read_hdf(path, "df")
26+
tm.assert_frame_equal(result, expected)
27+
28+
with ensure_clean_path("temp.h5") as path:
29+
with HDFStore(path) as store:
30+
store.put("df", sdf)
31+
result = read_hdf(path, "df")
32+
tm.assert_frame_equal(result, expected)
33+
34+
def test_supported_for_subclass_series(self):
35+
class SubSeries(Series):
36+
@property
37+
def _constructor(self):
38+
return SubSeries
39+
40+
data = [1, 2, 3]
41+
sser = SubSeries(data, dtype=np.intp)
42+
43+
expected = Series(data, dtype=np.intp)
44+
45+
with ensure_clean_path("temp.h5") as path:
46+
sser.to_hdf(path, "ser")
47+
result = read_hdf(path, "ser")
48+
tm.assert_series_equal(result, expected)
49+
50+
with ensure_clean_path("temp.h5") as path:
51+
with HDFStore(path) as store:
52+
store.put("ser", sser)
53+
result = read_hdf(path, "ser")
54+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)