From 30cbd6a2409e5f4c04b61944ffdc3efbf96dc5dd Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 25 Jan 2025 22:11:44 -0500 Subject: [PATCH 1/3] TST(string dtype): Resolve pytable xfails --- pandas/io/pytables.py | 11 +- pandas/tests/io/pytables/test_append.py | 84 ++++++++---- pandas/tests/io/pytables/test_categorical.py | 3 - pandas/tests/io/pytables/test_complex.py | 6 - pandas/tests/io/pytables/test_errors.py | 14 +- .../tests/io/pytables/test_file_handling.py | 6 +- pandas/tests/io/pytables/test_keys.py | 3 - pandas/tests/io/pytables/test_read.py | 129 ++++++++++-------- pandas/tests/io/pytables/test_round_trip.py | 75 +++++++--- pandas/tests/io/pytables/test_select.py | 75 +++++++--- pandas/tests/io/pytables/test_store.py | 111 +++++++++++---- pandas/tests/io/pytables/test_timezones.py | 6 - 12 files changed, 339 insertions(+), 184 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 2f8096746318b..69e80e57d8a3f 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3382,6 +3382,8 @@ def read( if ( using_string_dtype() and isinstance(values, np.ndarray) + # TODO: Should is_string_array return True for an empty object ndarray? + and values.size != 0 and is_string_array(values, skipna=True) ): df = df.astype(StringDtype(na_value=np.nan)) @@ -4148,6 +4150,9 @@ def _create_axes( meta = "category" metadata = np.asarray(data_converted.categories).ravel() + if isinstance(blk.dtype, StringDtype): + meta = str(blk.dtype) + data, dtype_name = _get_data_and_dtype_name(data_converted) col = klass( @@ -4407,7 +4412,8 @@ def read_column( errors=self.errors, ) cvs = col_values[1] - return Series(cvs, name=column, copy=False) + dtype = getattr(self.table.attrs, f"{column}_meta") + return Series(cvs, name=column, copy=False, dtype=dtype) raise KeyError(f"column [{column}] not found in the table") @@ -4523,7 +4529,6 @@ def write_data(self, chunksize: int | None, dropna: bool = False) -> None: mask = isna(a.data).all(axis=0) if isinstance(mask, np.ndarray): masks.append(mask.astype("u1", copy=False)) - # consolidate masks if len(masks): mask = masks[0] @@ -5112,6 +5117,8 @@ def _maybe_convert_for_string_atom( errors, columns: list[str], ): + if isinstance(bvalues.dtype, StringDtype): + bvalues = bvalues.to_numpy() if bvalues.dtype != object: return bvalues diff --git a/pandas/tests/io/pytables/test_append.py b/pandas/tests/io/pytables/test_append.py index 47658c0eb9012..baddb457cb16c 100644 --- a/pandas/tests/io/pytables/test_append.py +++ b/pandas/tests/io/pytables/test_append.py @@ -5,8 +5,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas._libs.tslibs import Timestamp from pandas.compat import PY312 @@ -27,7 +25,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] tables = pytest.importorskip("tables") @@ -40,7 +37,7 @@ def test_append(setup_path): # tables.NaturalNameWarning): df = DataFrame( np.random.default_rng(2).standard_normal((20, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=20, freq="B"), ) _maybe_remove(store, "df1") @@ -203,7 +200,7 @@ def test_append_some_nans(setup_path): tm.assert_frame_equal(store["df3"], df3, check_index_type=True) -def test_append_all_nans(setup_path): +def test_append_all_nans(setup_path, using_infer_string): with ensure_clean_store(setup_path) as store: df = DataFrame( { @@ -255,7 +252,13 @@ def test_append_all_nans(setup_path): _maybe_remove(store, "df") store.append("df", df[:10], dropna=True) store.append("df", df[10:], dropna=True) - tm.assert_frame_equal(store["df"], df, check_index_type=True) + result = store["df"] + expected = df + if using_infer_string: + # TODO: Test is incorrect when not using_infer_string. + # Should take the last 4 rows uncondiationally. + expected = expected[16:] + tm.assert_frame_equal(result, expected, check_index_type=True) _maybe_remove(store, "df2") store.append("df2", df[:10], dropna=False) @@ -294,7 +297,7 @@ def test_append_frame_column_oriented(setup_path, request): # column oriented df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df.index = df.index._with_freq(None) # freq doesn't round-trip @@ -426,7 +429,7 @@ def check_col(key, name, size): { "A": [0.0, 1.0, 2.0, 3.0, 4.0], "B": [0.0, 1.0, 0.0, 1.0, 0.0], - "C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object), + "C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"]), "D": date_range("20130101", periods=5), } ).set_index("C") @@ -453,7 +456,7 @@ def check_col(key, name, size): _maybe_remove(store, "df") df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df["string"] = "foo" @@ -517,7 +520,7 @@ def test_append_with_data_columns(setup_path): with ensure_clean_store(setup_path) as store: df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df.iloc[0, df.columns.get_loc("B")] = 1.0 @@ -693,8 +696,12 @@ def test_append_misc(setup_path): with ensure_clean_store(setup_path) as store: df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) store.append("df", df, chunksize=1) result = store.select("df") @@ -710,8 +717,12 @@ def test_append_misc_chunksize(setup_path, chunksize): # more chunksize in append tests df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) df["string"] = "foo" df["float322"] = 1.0 @@ -747,15 +758,19 @@ def test_append_misc_empty_frame(setup_path): tm.assert_frame_equal(store.select("df2"), df) -def test_append_raise(setup_path): +def test_append_raise(setup_path, using_infer_string): with ensure_clean_store(setup_path) as store: # test append with invalid input to get good error messages # list in column df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) df["invalid"] = [["a"]] * len(df) assert df.dtypes["invalid"] == np.object_ @@ -775,8 +790,12 @@ def test_append_raise(setup_path): # datetime with embedded nans as object df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) s = Series(datetime.datetime(2001, 1, 2), index=df.index) s = s.astype(object) @@ -803,8 +822,12 @@ def test_append_raise(setup_path): # appending an incompatible table df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) store.append("df", df) @@ -822,10 +845,11 @@ def test_append_raise(setup_path): df["foo"] = Timestamp("20130101") store.append("df", df) df["foo"] = "bar" + shape = "(30,)" if using_infer_string else "(1, 30)" msg = re.escape( "invalid combination of [values_axes] on appending data " "[name->values_block_1,cname->values_block_1," - "dtype->bytes24,kind->string,shape->(1, 30)] " + f"dtype->bytes24,kind->string,shape->{shape}] " "vs current table " "[name->values_block_1,cname->values_block_1," "dtype->datetime64[s],kind->datetime64[s],shape->None]" @@ -884,7 +908,9 @@ def test_append_with_timedelta(setup_path): def test_append_to_multiple(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) @@ -921,12 +947,16 @@ def test_append_to_multiple(setup_path): def test_append_to_multiple_dropna(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ).rename(columns="{}_2".format) df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan @@ -946,7 +976,9 @@ def test_append_to_multiple_dropna(setup_path): def test_append_to_multiple_dropna_false(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) diff --git a/pandas/tests/io/pytables/test_categorical.py b/pandas/tests/io/pytables/test_categorical.py index 998021bad9001..0f8d08f60843c 100644 --- a/pandas/tests/io/pytables/test_categorical.py +++ b/pandas/tests/io/pytables/test_categorical.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas import ( Categorical, DataFrame, @@ -18,7 +16,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] diff --git a/pandas/tests/io/pytables/test_complex.py b/pandas/tests/io/pytables/test_complex.py index d140cfc941e16..c5cac5a5caf09 100644 --- a/pandas/tests/io/pytables/test_complex.py +++ b/pandas/tests/io/pytables/test_complex.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - import pandas as pd from pandas import ( DataFrame, @@ -13,10 +11,6 @@ from pandas.io.pytables import read_hdf -pytestmark = pytest.mark.xfail( - using_string_dtype(), reason="TODO(infer_string)", strict=False -) - def test_complex_fixed(tmp_path, setup_path): df = DataFrame( diff --git a/pandas/tests/io/pytables/test_errors.py b/pandas/tests/io/pytables/test_errors.py index c31b9989ef35e..cc2a15fd0aaf0 100644 --- a/pandas/tests/io/pytables/test_errors.py +++ b/pandas/tests/io/pytables/test_errors.py @@ -5,8 +5,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas import ( CategoricalIndex, DataFrame, @@ -26,7 +24,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] @@ -93,9 +90,14 @@ def test_unimplemented_dtypes_table_columns(setup_path): with ensure_clean_store(setup_path) as store: # this fails because we have a date in the object block...... - msg = re.escape( - """Cannot serialize the column [datetime1] -because its data contents are not [string] but [date] object dtype""" + msg = "|".join( + [ + re.escape( + "Cannot serialize the column [datetime1] because its data contents " + "are not [string] but [date] object dtype" + ), + re.escape("[date] is not implemented as a table column"), + ] ) with pytest.raises(TypeError, match=msg): store.append("df_unimplemented", df) diff --git a/pandas/tests/io/pytables/test_file_handling.py b/pandas/tests/io/pytables/test_file_handling.py index 16c3c6798ff76..8d397f03875d8 100644 --- a/pandas/tests/io/pytables/test_file_handling.py +++ b/pandas/tests/io/pytables/test_file_handling.py @@ -3,8 +3,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas.compat import ( PY311, is_ci_environment, @@ -329,7 +327,6 @@ def test_complibs(tmp_path, lvl, lib, request): assert node.filters.complib == lib -@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False) @pytest.mark.skipif( not is_platform_little_endian(), reason="reason platform is not little endian" ) @@ -347,7 +344,6 @@ def test_encoding(setup_path): tm.assert_frame_equal(result, expected) -@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False) @pytest.mark.parametrize( "val", [ @@ -362,7 +358,7 @@ def test_encoding(setup_path): [b"A\xf8\xfc", np.nan, b"", b"b", b"c"], ], ) -@pytest.mark.parametrize("dtype", ["category", object]) +@pytest.mark.parametrize("dtype", ["category", None]) def test_latin_encoding(tmp_path, setup_path, dtype, val): enc = "latin-1" nan_rep = "" diff --git a/pandas/tests/io/pytables/test_keys.py b/pandas/tests/io/pytables/test_keys.py index 7d0802dcf2e47..43ec6e8c322e0 100644 --- a/pandas/tests/io/pytables/test_keys.py +++ b/pandas/tests/io/pytables/test_keys.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas import ( DataFrame, HDFStore, @@ -17,7 +15,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] diff --git a/pandas/tests/io/pytables/test_read.py b/pandas/tests/io/pytables/test_read.py index 8ae87d4bab52d..06f6276e4074a 100644 --- a/pandas/tests/io/pytables/test_read.py +++ b/pandas/tests/io/pytables/test_read.py @@ -5,8 +5,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas.compat import is_platform_windows import pandas as pd @@ -28,7 +26,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] @@ -78,75 +75,81 @@ def test_read_missing_key_opened_store(tmp_path, setup_path): def test_read_column(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df") - # GH 17912 - # HDFStore.select_column should raise a KeyError - # exception if the key is not a valid store - with pytest.raises(KeyError, match="No object named df in the file"): - store.select_column("df", "index") - - store.append("df", df) - # error - with pytest.raises( - KeyError, match=re.escape("'column [foo] not found in the table'") - ): - store.select_column("df", "foo") - - msg = re.escape("select_column() got an unexpected keyword argument 'where'") - with pytest.raises(TypeError, match=msg): - store.select_column("df", "index", where=["index>5"]) - - # valid - result = store.select_column("df", "index") - tm.assert_almost_equal(result.values, Series(df.index).values) - assert isinstance(result, Series) - - # not a data indexable column - msg = re.escape( - "column [values_block_0] can not be extracted individually; " - "it is not data indexable" - ) - with pytest.raises(ValueError, match=msg): - store.select_column("df", "values_block_0") - - # a data column - df2 = df.copy() - df2["string"] = "foo" - store.append("df2", df2, data_columns=["string"]) - result = store.select_column("df2", "string") - tm.assert_almost_equal(result.values, df2["string"].values) + # # GH 17912 + # # HDFStore.select_column should raise a KeyError + # # exception if the key is not a valid store + # with pytest.raises(KeyError, match="No object named df in the file"): + # store.select_column("df", "index") + # + # store.append("df", df) + # # error + # with pytest.raises( + # KeyError, match=re.escape("'column [foo] not found in the table'") + # ): + # store.select_column("df", "foo") + # + # msg = re.escape("select_column() got an unexpected keyword argument 'where'") + # with pytest.raises(TypeError, match=msg): + # store.select_column("df", "index", where=["index>5"]) + # + # # valid + # result = store.select_column("df", "index") + # tm.assert_almost_equal(result.values, Series(df.index).values) + # assert isinstance(result, Series) + # + # # not a data indexable column + # msg = re.escape( + # "column [values_block_0] can not be extracted individually; " + # "it is not data indexable" + # ) + # with pytest.raises(ValueError, match=msg): + # store.select_column("df", "values_block_0") + # + # # a data column + # df2 = df.copy() + # df2["string"] = "foo" + # store.append("df2", df2, data_columns=["string"]) + # result = store.select_column("df2", "string") + # tm.assert_almost_equal(result.values, df2["string"].values) # a data column with NaNs, result excludes the NaNs df3 = df.copy() df3["string"] = "foo" df3.loc[df3.index[4:6], "string"] = np.nan store.append("df3", df3, data_columns=["string"]) - result = store.select_column("df3", "string") - tm.assert_almost_equal(result.values, df3["string"].values) - - # start/stop - result = store.select_column("df3", "string", start=2) - tm.assert_almost_equal(result.values, df3["string"].values[2:]) - - result = store.select_column("df3", "string", start=-2) - tm.assert_almost_equal(result.values, df3["string"].values[-2:]) - - result = store.select_column("df3", "string", stop=2) - tm.assert_almost_equal(result.values, df3["string"].values[:2]) - - result = store.select_column("df3", "string", stop=-2) - tm.assert_almost_equal(result.values, df3["string"].values[:-2]) - - result = store.select_column("df3", "string", start=2, stop=-2) - tm.assert_almost_equal(result.values, df3["string"].values[2:-2]) - + # result = store.select_column("df3", "string") + # tm.assert_almost_equal(result.values, df3["string"].values) + # + # # start/stop + # result = store.select_column("df3", "string", start=2) + # tm.assert_almost_equal(result.values, df3["string"].values[2:]) + # + # result = store.select_column("df3", "string", start=-2) + # tm.assert_almost_equal(result.values, df3["string"].values[-2:]) + # + # result = store.select_column("df3", "string", stop=2) + # tm.assert_almost_equal(result.values, df3["string"].values[:2]) + # + # result = store.select_column("df3", "string", stop=-2) + # tm.assert_almost_equal(result.values, df3["string"].values[:-2]) + # + # result = store.select_column("df3", "string", start=2, stop=-2) + # tm.assert_almost_equal(result.values, df3["string"].values[2:-2]) + + print(df3) + print(df3["string"].values) result = store.select_column("df3", "string", start=-2, stop=2) + print(result) + print(result.values) tm.assert_almost_equal(result.values, df3["string"].values[-2:2]) # GH 10392 - make sure column name is preserved @@ -175,7 +178,7 @@ def test_pytables_native2_read(datapath): assert isinstance(d1, DataFrame) -def test_read_hdf_open_store(tmp_path, setup_path): +def test_read_hdf_open_store(tmp_path, setup_path, using_infer_string): # GH10330 # No check for non-string path_or-buf, and no test of open store df = DataFrame( @@ -187,6 +190,12 @@ def test_read_hdf_open_store(tmp_path, setup_path): df = df.set_index(keys="E", append=True) path = tmp_path / setup_path + if using_infer_string: + # TODO(infer_string) make this work for string dtype + msg = "Saving a MultiIndex with an extension dtype is not supported." + with pytest.raises(NotImplementedError, match=msg): + df.to_hdf(path, key="df", mode="w") + return df.to_hdf(path, key="df", mode="w") direct = read_hdf(path, "df") with HDFStore(path, mode="r") as store: diff --git a/pandas/tests/io/pytables/test_round_trip.py b/pandas/tests/io/pytables/test_round_trip.py index 6b98a720e4299..179a182276e98 100644 --- a/pandas/tests/io/pytables/test_round_trip.py +++ b/pandas/tests/io/pytables/test_round_trip.py @@ -4,8 +4,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas._libs.tslibs import Timestamp from pandas.compat import is_platform_windows @@ -28,7 +26,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] @@ -49,8 +46,12 @@ def roundtrip(key, obj, **kwargs): o = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) tm.assert_frame_equal(o, roundtrip("frame", o)) @@ -150,8 +151,12 @@ def test_api_invalid(tmp_path, setup_path): # Invalid. df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) msg = "Can only append to Tables" @@ -201,7 +206,7 @@ def test_put_integer(setup_path): _check_roundtrip(df, tm.assert_frame_equal, setup_path) -def test_table_values_dtypes_roundtrip(setup_path): +def test_table_values_dtypes_roundtrip(setup_path, using_infer_string): with ensure_clean_store(setup_path) as store: df1 = DataFrame({"a": [1, 2, 3]}, dtype="f8") store.append("df_f8", df1) @@ -249,6 +254,7 @@ def test_table_values_dtypes_roundtrip(setup_path): store.append("df_mixed_dtypes1", df1) result = store.select("df_mixed_dtypes1").dtypes.value_counts() result.index = [str(i) for i in result.index] + str_dtype = "str" if using_infer_string else "object" expected = Series( { "float32": 2, @@ -258,7 +264,7 @@ def test_table_values_dtypes_roundtrip(setup_path): "int16": 1, "int8": 1, "int64": 1, - "object": 1, + str_dtype: 1, "datetime64[s]": 2, "datetime64[ms]": 1, "datetime64[ns]": 1, @@ -280,10 +286,22 @@ def test_series(setup_path): ) _check_roundtrip(ts, tm.assert_series_equal, path=setup_path) - ts2 = Series(ts.index, Index(ts.index, dtype=object)) + ts2 = Series( + ts.index, + Index( + ts.index, + ), + ) _check_roundtrip(ts2, tm.assert_series_equal, path=setup_path) - ts3 = Series(ts.values, Index(np.asarray(ts.index, dtype=object), dtype=object)) + ts3 = Series( + ts.values, + Index( + np.asarray( + ts.index, + ), + ), + ) _check_roundtrip( ts3, tm.assert_series_equal, path=setup_path, check_index_type=False ) @@ -373,8 +391,12 @@ def test_timeseries_preepoch(setup_path, request): def test_frame(compression, setup_path): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) # put in some random NAs @@ -390,7 +412,9 @@ def test_frame(compression, setup_path): tdf = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) _check_roundtrip( @@ -405,7 +429,10 @@ def test_frame(compression, setup_path): assert recons._mgr.is_consolidated() # empty - _check_roundtrip(df[:0], tm.assert_frame_equal, path=setup_path) + df2 = df[:0] + # df2 has inferred_type as string + df2.index = Index([]) + _check_roundtrip(df2[:0], tm.assert_frame_equal, path=setup_path) def test_empty_series_frame(setup_path): @@ -437,9 +464,17 @@ def test_can_serialize_dates(setup_path): _check_roundtrip(frame, tm.assert_frame_equal, path=setup_path) -def test_store_hierarchical(setup_path, multiindex_dataframe_random_data): +def test_store_hierarchical( + setup_path, using_infer_string, multiindex_dataframe_random_data +): frame = multiindex_dataframe_random_data + if using_infer_string: + # TODO(infer_string) make this work for string dtype + msg = "Saving a MultiIndex with an extension dtype is not supported." + with pytest.raises(NotImplementedError, match=msg): + _check_roundtrip(frame, tm.assert_frame_equal, path=setup_path) + return _check_roundtrip(frame, tm.assert_frame_equal, path=setup_path) _check_roundtrip(frame.T, tm.assert_frame_equal, path=setup_path) _check_roundtrip(frame["A"], tm.assert_series_equal, path=setup_path) @@ -458,8 +493,12 @@ def test_store_mixed(compression, setup_path): def _make_one(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) df["obj1"] = "foo" df["obj2"] = "bar" diff --git a/pandas/tests/io/pytables/test_select.py b/pandas/tests/io/pytables/test_select.py index 4b20b929ef447..4de2fe843e3f4 100644 --- a/pandas/tests/io/pytables/test_select.py +++ b/pandas/tests/io/pytables/test_select.py @@ -1,8 +1,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas._libs.tslibs import Timestamp from pandas.compat import PY312 @@ -29,7 +27,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] @@ -138,7 +135,9 @@ def test_select(setup_path): # select with columns= df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) _maybe_remove(store, "df") @@ -278,8 +277,12 @@ def test_select_dtypes(setup_path, request): with ensure_clean_store(setup_path) as store: df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) expected = df[df["A"] > 0] @@ -350,7 +353,9 @@ def test_select_iterator(tmp_path, setup_path): with ensure_clean_store(setup_path) as store: df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) _maybe_remove(store, "df") @@ -375,7 +380,9 @@ def test_select_iterator(tmp_path, setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df.to_hdf(path, key="df_non_table") @@ -391,7 +398,9 @@ def test_select_iterator(tmp_path, setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df.to_hdf(path, key="df", format="table") @@ -408,7 +417,9 @@ def test_select_iterator(tmp_path, setup_path): with ensure_clean_store(setup_path) as store: df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) store.append("df1", df1, data_columns=True) @@ -436,7 +447,9 @@ def test_select_iterator_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -471,7 +484,9 @@ def test_select_iterator_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -513,7 +528,9 @@ def test_select_iterator_non_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -547,7 +564,9 @@ def test_select_iterator_non_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -571,7 +590,9 @@ def test_select_iterator_many_empty_frames(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -623,7 +644,9 @@ def test_select_iterator_many_empty_frames(setup_path): def test_frame_select(setup_path, request): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -655,7 +678,9 @@ def test_frame_select(setup_path, request): # invalid terms df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) store.append("df_time", df) @@ -674,7 +699,9 @@ def test_frame_select_complex(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df["string"] = "foo" @@ -791,7 +818,9 @@ def test_invalid_filtering(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -813,7 +842,9 @@ def test_string_select(setup_path): with ensure_clean_store(setup_path) as store: df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -857,7 +888,9 @@ def test_string_select(setup_path): def test_select_as_multiple(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index a6fe9529c594a..428cb473ff399 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -37,7 +37,6 @@ pytestmark = [ pytest.mark.single_cpu, - pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), ] tables = pytest.importorskip("tables") @@ -110,7 +109,7 @@ def test_iter_empty(setup_path): assert list(store) == [] -def test_repr(setup_path, performance_warning): +def test_repr(setup_path, performance_warning, using_infer_string): with ensure_clean_store(setup_path) as store: repr(store) store.info() @@ -145,7 +144,9 @@ def test_repr(setup_path, performance_warning): df.loc[df.index[3:6], ["obj1"]] = np.nan df = df._consolidate() - with tm.assert_produces_warning(performance_warning): + warning = None if using_infer_string else performance_warning + msg = "cannot\nmap directly to c-types .* dtype='object'" + with tm.assert_produces_warning(warning, match=msg): store["df"] = df # make a random group in hdf space @@ -316,7 +317,9 @@ def test_getattr(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) store["df"] = df @@ -369,7 +372,9 @@ def test_to_hdf_with_min_itemsize(tmp_path, setup_path): { "A": [0.0, 1.0, 2.0, 3.0, 4.0], "B": [0.0, 1.0, 0.0, 1.0, 0.0], - "C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"], dtype=object), + "C": Index( + ["foo1", "foo2", "foo3", "foo4", "foo5"], + ), "D": date_range("20130101", periods=5), } ).set_index("C") @@ -385,6 +390,10 @@ def test_to_hdf_with_min_itemsize(tmp_path, setup_path): tm.assert_series_equal(read_hdf(path, "ss4"), concat([df["B"], df2["B"]])) +@pytest.mark.xfail( + using_string_dtype(), + reason="'utf-8' can't encode '\ud800': surrogates not allowed", +) @pytest.mark.parametrize("format", ["fixed", "table"]) def test_to_hdf_errors(tmp_path, format, setup_path): data = ["\ud800foo"] @@ -406,7 +415,9 @@ def col(t, column): # data columns df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df["string"] = "foo" @@ -441,7 +452,9 @@ def col(t, column): # data columns df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df["string"] = "foo" @@ -483,8 +496,12 @@ def test_table_mixed_dtypes(setup_path): # frame df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) df["obj1"] = "foo" df["obj2"] = "bar" @@ -539,8 +556,12 @@ def test_remove(setup_path): ) df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) store["a"] = ts store["b"] = df @@ -603,8 +624,12 @@ def test_same_name_scoping(setup_path): def test_store_index_name(setup_path): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) df.index.name = "foo" @@ -650,8 +675,12 @@ def test_store_index_name_numpy_str(tmp_path, table_format, setup_path, unit, tz def test_store_series_name(setup_path): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) series = df["A"] @@ -665,7 +694,9 @@ def test_overwrite_node(setup_path): with ensure_clean_store(setup_path) as store: store["a"] = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) ts = Series( @@ -679,7 +710,9 @@ def test_overwrite_node(setup_path): def test_coordinates(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -714,7 +747,9 @@ def test_coordinates(setup_path): _maybe_remove(store, "df2") df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index(list("ABCD"), dtype=object), + columns=Index( + list("ABCD"), + ), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) @@ -870,8 +905,12 @@ def test_start_stop_fixed(setup_path): # sparse; not implemented df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) df.iloc[3:5, 1:3] = np.nan df.iloc[8:10, -2] = np.nan @@ -904,8 +943,12 @@ def test_select_filter_corner(setup_path, request): def test_path_pathlib(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) result = tm.round_trip_pathlib( @@ -934,8 +977,12 @@ def test_contiguous_mixed_data_table(start, stop, setup_path): def test_path_pathlib_hdfstore(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) def writer(path): @@ -953,8 +1000,12 @@ def reader(path): def test_pickle_path_localpath(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) result = tm.round_trip_pathlib( lambda p: df.to_hdf(p, key="df"), lambda p: read_hdf(p, "df") @@ -966,8 +1017,12 @@ def test_pickle_path_localpath(): def test_copy(propindexes): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index( + list("ABCD"), + ), + index=Index( + [f"i-{i}" for i in range(30)], + ), ) with tm.ensure_clean() as path: diff --git a/pandas/tests/io/pytables/test_timezones.py b/pandas/tests/io/pytables/test_timezones.py index 8f179f844e4d0..9192804e49bd1 100644 --- a/pandas/tests/io/pytables/test_timezones.py +++ b/pandas/tests/io/pytables/test_timezones.py @@ -6,8 +6,6 @@ import numpy as np import pytest -from pandas._config import using_string_dtype - from pandas._libs.tslibs.timezones import maybe_get_tz import pandas.util._test_decorators as td @@ -25,10 +23,6 @@ ensure_clean_store, ) -pytestmark = pytest.mark.xfail( - using_string_dtype(), reason="TODO(infer_string)", strict=False -) - def _compare_with_tz(a, b): tm.assert_frame_equal(a, b) From 2b09a00ff334a3f2f9c75fe9ff9bf6e5bac9163d Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 25 Jan 2025 22:23:39 -0500 Subject: [PATCH 2/3] Cleanup --- pandas/tests/io/pytables/test_append.py | 48 ++------ pandas/tests/io/pytables/test_read.py | 118 ++++++++++---------- pandas/tests/io/pytables/test_round_trip.py | 49 ++------ pandas/tests/io/pytables/test_select.py | 73 +++--------- pandas/tests/io/pytables/test_store.py | 100 +++++------------ 5 files changed, 122 insertions(+), 266 deletions(-) diff --git a/pandas/tests/io/pytables/test_append.py b/pandas/tests/io/pytables/test_append.py index baddb457cb16c..b42f160be8c8d 100644 --- a/pandas/tests/io/pytables/test_append.py +++ b/pandas/tests/io/pytables/test_append.py @@ -696,12 +696,8 @@ def test_append_misc(setup_path): with ensure_clean_store(setup_path) as store: df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) store.append("df", df, chunksize=1) result = store.select("df") @@ -717,12 +713,8 @@ def test_append_misc_chunksize(setup_path, chunksize): # more chunksize in append tests df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) df["string"] = "foo" df["float322"] = 1.0 @@ -765,12 +757,8 @@ def test_append_raise(setup_path, using_infer_string): # list in column df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) df["invalid"] = [["a"]] * len(df) assert df.dtypes["invalid"] == np.object_ @@ -822,12 +810,8 @@ def test_append_raise(setup_path, using_infer_string): # appending an incompatible table df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) store.append("df", df) @@ -908,9 +892,7 @@ def test_append_with_timedelta(setup_path): def test_append_to_multiple(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) @@ -947,16 +929,12 @@ def test_append_to_multiple(setup_path): def test_append_to_multiple_dropna(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ).rename(columns="{}_2".format) df1.iloc[1, df1.columns.get_indexer(["A", "B"])] = np.nan @@ -976,9 +954,7 @@ def test_append_to_multiple_dropna(setup_path): def test_append_to_multiple_dropna_false(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) diff --git a/pandas/tests/io/pytables/test_read.py b/pandas/tests/io/pytables/test_read.py index 06f6276e4074a..01263241ea90b 100644 --- a/pandas/tests/io/pytables/test_read.py +++ b/pandas/tests/io/pytables/test_read.py @@ -75,81 +75,75 @@ def test_read_missing_key_opened_store(tmp_path, setup_path): def test_read_column(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) with ensure_clean_store(setup_path) as store: _maybe_remove(store, "df") - # # GH 17912 - # # HDFStore.select_column should raise a KeyError - # # exception if the key is not a valid store - # with pytest.raises(KeyError, match="No object named df in the file"): - # store.select_column("df", "index") - # - # store.append("df", df) - # # error - # with pytest.raises( - # KeyError, match=re.escape("'column [foo] not found in the table'") - # ): - # store.select_column("df", "foo") - # - # msg = re.escape("select_column() got an unexpected keyword argument 'where'") - # with pytest.raises(TypeError, match=msg): - # store.select_column("df", "index", where=["index>5"]) - # - # # valid - # result = store.select_column("df", "index") - # tm.assert_almost_equal(result.values, Series(df.index).values) - # assert isinstance(result, Series) - # - # # not a data indexable column - # msg = re.escape( - # "column [values_block_0] can not be extracted individually; " - # "it is not data indexable" - # ) - # with pytest.raises(ValueError, match=msg): - # store.select_column("df", "values_block_0") - # - # # a data column - # df2 = df.copy() - # df2["string"] = "foo" - # store.append("df2", df2, data_columns=["string"]) - # result = store.select_column("df2", "string") - # tm.assert_almost_equal(result.values, df2["string"].values) + # GH 17912 + # HDFStore.select_column should raise a KeyError + # exception if the key is not a valid store + with pytest.raises(KeyError, match="No object named df in the file"): + store.select_column("df", "index") + + store.append("df", df) + # error + with pytest.raises( + KeyError, match=re.escape("'column [foo] not found in the table'") + ): + store.select_column("df", "foo") + + msg = re.escape("select_column() got an unexpected keyword argument 'where'") + with pytest.raises(TypeError, match=msg): + store.select_column("df", "index", where=["index>5"]) + + # valid + result = store.select_column("df", "index") + tm.assert_almost_equal(result.values, Series(df.index).values) + assert isinstance(result, Series) + + # not a data indexable column + msg = re.escape( + "column [values_block_0] can not be extracted individually; " + "it is not data indexable" + ) + with pytest.raises(ValueError, match=msg): + store.select_column("df", "values_block_0") + + # a data column + df2 = df.copy() + df2["string"] = "foo" + store.append("df2", df2, data_columns=["string"]) + result = store.select_column("df2", "string") + tm.assert_almost_equal(result.values, df2["string"].values) # a data column with NaNs, result excludes the NaNs df3 = df.copy() df3["string"] = "foo" df3.loc[df3.index[4:6], "string"] = np.nan store.append("df3", df3, data_columns=["string"]) - # result = store.select_column("df3", "string") - # tm.assert_almost_equal(result.values, df3["string"].values) - # - # # start/stop - # result = store.select_column("df3", "string", start=2) - # tm.assert_almost_equal(result.values, df3["string"].values[2:]) - # - # result = store.select_column("df3", "string", start=-2) - # tm.assert_almost_equal(result.values, df3["string"].values[-2:]) - # - # result = store.select_column("df3", "string", stop=2) - # tm.assert_almost_equal(result.values, df3["string"].values[:2]) - # - # result = store.select_column("df3", "string", stop=-2) - # tm.assert_almost_equal(result.values, df3["string"].values[:-2]) - # - # result = store.select_column("df3", "string", start=2, stop=-2) - # tm.assert_almost_equal(result.values, df3["string"].values[2:-2]) - - print(df3) - print(df3["string"].values) + result = store.select_column("df3", "string") + tm.assert_almost_equal(result.values, df3["string"].values) + + # start/stop + result = store.select_column("df3", "string", start=2) + tm.assert_almost_equal(result.values, df3["string"].values[2:]) + + result = store.select_column("df3", "string", start=-2) + tm.assert_almost_equal(result.values, df3["string"].values[-2:]) + + result = store.select_column("df3", "string", stop=2) + tm.assert_almost_equal(result.values, df3["string"].values[:2]) + + result = store.select_column("df3", "string", stop=-2) + tm.assert_almost_equal(result.values, df3["string"].values[:-2]) + + result = store.select_column("df3", "string", start=2, stop=-2) + tm.assert_almost_equal(result.values, df3["string"].values[2:-2]) + result = store.select_column("df3", "string", start=-2, stop=2) - print(result) - print(result.values) tm.assert_almost_equal(result.values, df3["string"].values[-2:2]) # GH 10392 - make sure column name is preserved diff --git a/pandas/tests/io/pytables/test_round_trip.py b/pandas/tests/io/pytables/test_round_trip.py index 179a182276e98..88081d120143c 100644 --- a/pandas/tests/io/pytables/test_round_trip.py +++ b/pandas/tests/io/pytables/test_round_trip.py @@ -46,12 +46,8 @@ def roundtrip(key, obj, **kwargs): o = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) tm.assert_frame_equal(o, roundtrip("frame", o)) @@ -151,12 +147,8 @@ def test_api_invalid(tmp_path, setup_path): # Invalid. df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) msg = "Can only append to Tables" @@ -288,20 +280,11 @@ def test_series(setup_path): ts2 = Series( ts.index, - Index( - ts.index, - ), + Index(ts.index), ) _check_roundtrip(ts2, tm.assert_series_equal, path=setup_path) - ts3 = Series( - ts.values, - Index( - np.asarray( - ts.index, - ), - ), - ) + ts3 = Series(ts.values, Index(np.asarray(ts.index))) _check_roundtrip( ts3, tm.assert_series_equal, path=setup_path, check_index_type=False ) @@ -391,12 +374,8 @@ def test_timeseries_preepoch(setup_path, request): def test_frame(compression, setup_path): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) # put in some random NAs @@ -412,9 +391,7 @@ def test_frame(compression, setup_path): tdf = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) _check_roundtrip( @@ -493,12 +470,8 @@ def test_store_mixed(compression, setup_path): def _make_one(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) df["obj1"] = "foo" df["obj2"] = "bar" diff --git a/pandas/tests/io/pytables/test_select.py b/pandas/tests/io/pytables/test_select.py index 4de2fe843e3f4..1d2712a25928f 100644 --- a/pandas/tests/io/pytables/test_select.py +++ b/pandas/tests/io/pytables/test_select.py @@ -135,9 +135,7 @@ def test_select(setup_path): # select with columns= df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) _maybe_remove(store, "df") @@ -277,12 +275,8 @@ def test_select_dtypes(setup_path, request): with ensure_clean_store(setup_path) as store: df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) expected = df[df["A"] > 0] @@ -353,9 +347,7 @@ def test_select_iterator(tmp_path, setup_path): with ensure_clean_store(setup_path) as store: df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) _maybe_remove(store, "df") @@ -380,9 +372,7 @@ def test_select_iterator(tmp_path, setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df.to_hdf(path, key="df_non_table") @@ -398,9 +388,7 @@ def test_select_iterator(tmp_path, setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df.to_hdf(path, key="df", format="table") @@ -417,9 +405,7 @@ def test_select_iterator(tmp_path, setup_path): with ensure_clean_store(setup_path) as store: df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) store.append("df1", df1, data_columns=True) @@ -447,9 +433,7 @@ def test_select_iterator_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -484,9 +468,7 @@ def test_select_iterator_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -528,9 +510,7 @@ def test_select_iterator_non_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -564,9 +544,7 @@ def test_select_iterator_non_complete_8014(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -590,9 +568,7 @@ def test_select_iterator_many_empty_frames(setup_path): with ensure_clean_store(setup_path) as store: expected = DataFrame( np.random.default_rng(2).standard_normal((100064, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=100064, freq="s"), ) _maybe_remove(store, "df") @@ -644,9 +620,7 @@ def test_select_iterator_many_empty_frames(setup_path): def test_frame_select(setup_path, request): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -678,9 +652,7 @@ def test_frame_select(setup_path, request): # invalid terms df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) store.append("df_time", df) @@ -699,9 +671,7 @@ def test_frame_select_complex(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df["string"] = "foo" @@ -818,9 +788,7 @@ def test_invalid_filtering(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -842,9 +810,7 @@ def test_string_select(setup_path): with ensure_clean_store(setup_path) as store: df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -888,9 +854,7 @@ def test_string_select(setup_path): def test_select_as_multiple(setup_path): df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) @@ -1091,7 +1055,6 @@ def test_select_large_integer(tmp_path): ), columns=["x", "y"], ) - result = None with HDFStore(path) as s: s.append("data", df, data_columns=True, index=False) result = s.select("data", where="y==-9223372036854775801").get("y").get(0) diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 428cb473ff399..9fcd75e752614 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -317,9 +317,7 @@ def test_getattr(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) store["df"] = df @@ -372,9 +370,7 @@ def test_to_hdf_with_min_itemsize(tmp_path, setup_path): { "A": [0.0, 1.0, 2.0, 3.0, 4.0], "B": [0.0, 1.0, 0.0, 1.0, 0.0], - "C": Index( - ["foo1", "foo2", "foo3", "foo4", "foo5"], - ), + "C": Index(["foo1", "foo2", "foo3", "foo4", "foo5"]), "D": date_range("20130101", periods=5), } ).set_index("C") @@ -415,9 +411,7 @@ def col(t, column): # data columns df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df["string"] = "foo" @@ -452,9 +446,7 @@ def col(t, column): # data columns df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df["string"] = "foo" @@ -496,12 +488,8 @@ def test_table_mixed_dtypes(setup_path): # frame df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) df["obj1"] = "foo" df["obj2"] = "bar" @@ -556,12 +544,8 @@ def test_remove(setup_path): ) df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) store["a"] = ts store["b"] = df @@ -624,12 +608,8 @@ def test_same_name_scoping(setup_path): def test_store_index_name(setup_path): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) df.index.name = "foo" @@ -675,12 +655,8 @@ def test_store_index_name_numpy_str(tmp_path, table_format, setup_path, unit, tz def test_store_series_name(setup_path): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) series = df["A"] @@ -694,9 +670,7 @@ def test_overwrite_node(setup_path): with ensure_clean_store(setup_path) as store: store["a"] = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) ts = Series( @@ -710,9 +684,7 @@ def test_overwrite_node(setup_path): def test_coordinates(setup_path): df = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) @@ -747,9 +719,7 @@ def test_coordinates(setup_path): _maybe_remove(store, "df2") df1 = DataFrame( np.random.default_rng(2).standard_normal((10, 4)), - columns=Index( - list("ABCD"), - ), + columns=Index(list("ABCD")), index=date_range("2000-01-01", periods=10, freq="B"), ) df2 = df1.copy().rename(columns="{}_2".format) @@ -905,12 +875,8 @@ def test_start_stop_fixed(setup_path): # sparse; not implemented df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) df.iloc[3:5, 1:3] = np.nan df.iloc[8:10, -2] = np.nan @@ -943,12 +909,8 @@ def test_select_filter_corner(setup_path, request): def test_path_pathlib(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) result = tm.round_trip_pathlib( @@ -977,12 +939,8 @@ def test_contiguous_mixed_data_table(start, stop, setup_path): def test_path_pathlib_hdfstore(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) def writer(path): @@ -1000,12 +958,8 @@ def reader(path): def test_pickle_path_localpath(): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) result = tm.round_trip_pathlib( lambda p: df.to_hdf(p, key="df"), lambda p: read_hdf(p, "df") @@ -1017,12 +971,8 @@ def test_pickle_path_localpath(): def test_copy(propindexes): df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) with tm.ensure_clean() as path: From 9b2d6895e6b7fb42154f9fdd358bc429ef277513 Mon Sep 17 00:00:00 2001 From: richard Date: Sat, 25 Jan 2025 22:27:22 -0500 Subject: [PATCH 3/3] Cleanup --- pandas/tests/io/pytables/test_append.py | 12 +++--------- pandas/tests/io/pytables/test_categorical.py | 4 +--- pandas/tests/io/pytables/test_errors.py | 4 +--- pandas/tests/io/pytables/test_file_handling.py | 4 +--- pandas/tests/io/pytables/test_keys.py | 4 +--- pandas/tests/io/pytables/test_put.py | 4 +--- pandas/tests/io/pytables/test_read.py | 4 +--- pandas/tests/io/pytables/test_round_trip.py | 4 +--- pandas/tests/io/pytables/test_select.py | 4 +--- pandas/tests/io/pytables/test_store.py | 4 +--- 10 files changed, 12 insertions(+), 36 deletions(-) diff --git a/pandas/tests/io/pytables/test_append.py b/pandas/tests/io/pytables/test_append.py index b42f160be8c8d..c708153941a85 100644 --- a/pandas/tests/io/pytables/test_append.py +++ b/pandas/tests/io/pytables/test_append.py @@ -23,9 +23,7 @@ ensure_clean_store, ) -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] tables = pytest.importorskip("tables") @@ -778,12 +776,8 @@ def test_append_raise(setup_path, using_infer_string): # datetime with embedded nans as object df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index( - list("ABCD"), - ), - index=Index( - [f"i-{i}" for i in range(30)], - ), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) s = Series(datetime.datetime(2001, 1, 2), index=df.index) s = s.astype(object) diff --git a/pandas/tests/io/pytables/test_categorical.py b/pandas/tests/io/pytables/test_categorical.py index 0f8d08f60843c..ed2616b24cd71 100644 --- a/pandas/tests/io/pytables/test_categorical.py +++ b/pandas/tests/io/pytables/test_categorical.py @@ -14,9 +14,7 @@ ensure_clean_store, ) -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] def test_categorical(setup_path): diff --git a/pandas/tests/io/pytables/test_errors.py b/pandas/tests/io/pytables/test_errors.py index cc2a15fd0aaf0..e369ad45a4465 100644 --- a/pandas/tests/io/pytables/test_errors.py +++ b/pandas/tests/io/pytables/test_errors.py @@ -22,9 +22,7 @@ _maybe_adjust_name, ) -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] def test_pass_spec_to_storer(setup_path): diff --git a/pandas/tests/io/pytables/test_file_handling.py b/pandas/tests/io/pytables/test_file_handling.py index 8d397f03875d8..27b5d34146f85 100644 --- a/pandas/tests/io/pytables/test_file_handling.py +++ b/pandas/tests/io/pytables/test_file_handling.py @@ -33,9 +33,7 @@ from pandas.io import pytables from pandas.io.pytables import Term -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] @pytest.mark.parametrize("mode", ["r", "r+", "a", "w"]) diff --git a/pandas/tests/io/pytables/test_keys.py b/pandas/tests/io/pytables/test_keys.py index 43ec6e8c322e0..9c5fc8786c7c6 100644 --- a/pandas/tests/io/pytables/test_keys.py +++ b/pandas/tests/io/pytables/test_keys.py @@ -13,9 +13,7 @@ tables, ) -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] def test_keys(setup_path): diff --git a/pandas/tests/io/pytables/test_put.py b/pandas/tests/io/pytables/test_put.py index 66596f1138b96..c9fe6070b34c3 100644 --- a/pandas/tests/io/pytables/test_put.py +++ b/pandas/tests/io/pytables/test_put.py @@ -22,9 +22,7 @@ ) from pandas.util import _test_decorators as td -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] def test_format_type(tmp_path, setup_path): diff --git a/pandas/tests/io/pytables/test_read.py b/pandas/tests/io/pytables/test_read.py index 01263241ea90b..7a3a7339e7809 100644 --- a/pandas/tests/io/pytables/test_read.py +++ b/pandas/tests/io/pytables/test_read.py @@ -24,9 +24,7 @@ from pandas.io.pytables import TableIterator -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] def test_read_missing_key_close_store(tmp_path, setup_path): diff --git a/pandas/tests/io/pytables/test_round_trip.py b/pandas/tests/io/pytables/test_round_trip.py index 88081d120143c..d90adc6daebb0 100644 --- a/pandas/tests/io/pytables/test_round_trip.py +++ b/pandas/tests/io/pytables/test_round_trip.py @@ -24,9 +24,7 @@ ) from pandas.util import _test_decorators as td -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] def test_conv_read_write(): diff --git a/pandas/tests/io/pytables/test_select.py b/pandas/tests/io/pytables/test_select.py index 1d2712a25928f..5e76aae28c147 100644 --- a/pandas/tests/io/pytables/test_select.py +++ b/pandas/tests/io/pytables/test_select.py @@ -25,9 +25,7 @@ from pandas.io.pytables import Term -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] def test_select_columns_in_where(setup_path): diff --git a/pandas/tests/io/pytables/test_store.py b/pandas/tests/io/pytables/test_store.py index 9fcd75e752614..9980a1a0acd50 100644 --- a/pandas/tests/io/pytables/test_store.py +++ b/pandas/tests/io/pytables/test_store.py @@ -35,9 +35,7 @@ read_hdf, ) -pytestmark = [ - pytest.mark.single_cpu, -] +pytestmark = [pytest.mark.single_cpu] tables = pytest.importorskip("tables")