From 500ab5a9a2a6d386504345da73636b42a17485bc Mon Sep 17 00:00:00 2001 From: Jake Thomas Trevallion Date: Sun, 2 Feb 2025 10:00:09 +0000 Subject: [PATCH] Fix missed tests and correct mistake in error message. --- pandas/io/pytables.py | 4 ++-- pandas/tests/io/pytables/test_append.py | 6 +++++- pandas/tests/io/pytables/test_round_trip.py | 11 ++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index e387691d2ff64..56c09649587cc 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -3528,8 +3528,8 @@ def validate(self, other) -> None: if c == "values_axes" and sax.kind != oax.kind: raise TypeError( f"Cannot serialize the column [{oax.values[0]}] " - f"because its data contents are not [{oax.kind}] " - f"but [{sax.kind}] object dtype" + f"because its data contents are not [{sax.kind}] " + f"but [{oax.kind}] object dtype" ) # Fallback if other source of difference raise ValueError( diff --git a/pandas/tests/io/pytables/test_append.py b/pandas/tests/io/pytables/test_append.py index eb0dd7cd9c142..9940adb39a8d3 100644 --- a/pandas/tests/io/pytables/test_append.py +++ b/pandas/tests/io/pytables/test_append.py @@ -830,7 +830,11 @@ def test_append_raise(setup_path): df["foo"] = Timestamp("20130101") store.append("df", df) df["foo"] = "bar" - msg = re.escape("Cannot serialize the column [foo] but [string] object dtype") + msg = re.escape( + "Cannot serialize the column [foo] " + "because its data contents are not [string] " + "but [datetime64[s]] object dtype" + ) with pytest.raises(TypeError, match=msg): store.append("df", df) diff --git a/pandas/tests/io/pytables/test_round_trip.py b/pandas/tests/io/pytables/test_round_trip.py index 6b98a720e4299..bbb37eb64328b 100644 --- a/pandas/tests/io/pytables/test_round_trip.py +++ b/pandas/tests/io/pytables/test_round_trip.py @@ -213,14 +213,11 @@ def test_table_values_dtypes_roundtrip(setup_path): # incompatible dtype msg = re.escape( - "invalid combination of [values_axes] on appending data " - "[name->values_block_0,cname->values_block_0," - "dtype->float64,kind->float,shape->(1, 3)] vs " - "current table [name->values_block_0," - "cname->values_block_0,dtype->int64,kind->integer," - "shape->None]" + "Cannot serialize the column [a] " + "because its data contents are not [float] " + "but [integer] object dtype" ) - with pytest.raises(ValueError, match=msg): + with pytest.raises(TypeError, match=msg): store.append("df_i8", df1) # check creation/storage/retrieval of float32 (a bit hacky to