| 943 | |
| 944 | @pytest.mark.parametrize("propindexes", [True, False]) |
| 945 | def test_copy(propindexes, temp_file): |
| 946 | df = DataFrame( |
| 947 | 1.1 * np.arange(120).reshape((30, 4)), |
| 948 | columns=Index(list("ABCD")), |
| 949 | index=Index([f"i-{i}" for i in range(30)]), |
| 950 | ) |
| 951 | |
| 952 | with HDFStore(temp_file) as st: |
| 953 | st.append("df", df, data_columns=["A"]) |
| 954 | with tempfile.NamedTemporaryFile() as new_f: |
| 955 | with HDFStore(temp_file) as store: |
| 956 | with contextlib.closing( |
| 957 | store.copy(new_f.name, keys=None, propindexes=propindexes) |
| 958 | ) as tstore: |
| 959 | # check keys |
| 960 | keys = store.keys() |
| 961 | assert set(keys) == set(tstore.keys()) |
| 962 | # check indices & nrows |
| 963 | for k in tstore.keys(): |
| 964 | if tstore.get_storer(k).is_table: |
| 965 | new_t = tstore.get_storer(k) |
| 966 | orig_t = store.get_storer(k) |
| 967 | |
| 968 | assert orig_t.nrows == new_t.nrows |
| 969 | |
| 970 | # check propindixes |
| 971 | if propindexes: |
| 972 | for a in orig_t.axes: |
| 973 | if a.is_indexed: |
| 974 | assert new_t[a.name].is_indexed |
| 975 | |
| 976 | |
| 977 | def test_duplicate_column_name(temp_h5_path): |