-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_hdf and HDFStore for subclasses #38262
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
Changes from 4 commits
8d368fb
e38fae8
6633145
68b5e69
6088f4c
a25ad9f
618b263
41f8c58
6d8d758
0b338a8
41605c5
99720b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4888,6 +4888,50 @@ def test_unsuppored_hdf_file_error(self, datapath): | |
with pytest.raises(ValueError, match=message): | ||
pd.read_hdf(data_path) | ||
|
||
def test_supported_for_subclasses_dataframe(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put in a new file test_subclass.py There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to a separate file. Right, |
||
class SubDataFrame(DataFrame): | ||
@property | ||
def _constructor(self): | ||
return SubDataFrame | ||
|
||
data = {"a": [1, 2], "b": [3, 4]} | ||
sdf = SubDataFrame(data, dtype=np.intp) | ||
|
||
expected = DataFrame(data, dtype=np.intp) | ||
|
||
with ensure_clean_path("temp.h5") as path: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments as for series |
||
sdf.to_hdf(path, "df") | ||
result = read_hdf(path, "df") | ||
tm.assert_frame_equal(result, expected) | ||
|
||
with ensure_clean_path("temp.h5") as path: | ||
with HDFStore(path) as store: | ||
store.put("df", sdf) | ||
result = read_hdf(path, "df") | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_supported_for_subclasses_series(self): | ||
class SubSeries(Series): | ||
@property | ||
def _constructor(self): | ||
return SubSeries | ||
|
||
data = [1, 2, 3] | ||
sser = SubSeries(data, dtype=np.intp) | ||
|
||
expected = Series(data, dtype=np.intp) | ||
|
||
with ensure_clean_path("temp.h5") as path: | ||
sser.to_hdf(path, "ser") | ||
result = read_hdf(path, "ser") | ||
tm.assert_series_equal(result, expected) | ||
|
||
with ensure_clean_path("temp.h5") as path: | ||
with HDFStore(path) as store: | ||
store.put("ser", sser) | ||
result = read_hdf(path, "ser") | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.parametrize("bad_version", [(1, 2), (1,), [], "12", "123"]) | ||
def test_maybe_adjust_name_bad_version_raises(bad_version): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total nit but
black
permitting we could do