-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
TST(string dtype): Resolve xfails in pytables #60795
base: main
Are you sure you want to change the base?
Changes from 6 commits
120b0bd
adb0349
1413d27
70563ce
d12f66d
bc5b697
55ea98b
cb56243
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 |
---|---|---|
|
@@ -25,10 +25,7 @@ | |
ensure_clean_store, | ||
) | ||
|
||
pytestmark = [ | ||
pytest.mark.single_cpu, | ||
pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), | ||
] | ||
pytestmark = [pytest.mark.single_cpu] | ||
|
||
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" | ||
|
@@ -513,11 +516,12 @@ def test_append_with_empty_string(setup_path): | |
tm.assert_frame_equal(store.select("df"), df) | ||
|
||
|
||
@pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)") | ||
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 +697,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"), 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 +714,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"), 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 +751,15 @@ 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 +779,8 @@ 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 +807,8 @@ 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 +826,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)" | ||
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. Isn't this still a bug? Not sure why we would expect a different shape with the string data types? 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. I assumed it was due to array-backed vs 1d ndarray backed data. But I haven't checked too deeply. |
||
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 +889,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"), 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 +926,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"), 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 +951,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"), dtype=object), | ||
columns=Index(list("ABCD")), | ||
index=date_range("2000-01-01", periods=10, freq="B"), | ||
) | ||
df2 = df1.copy().rename(columns="{}_2".format) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,6 @@ | |
import numpy as np | ||
import pytest | ||
|
||
from pandas._config import using_string_dtype | ||
|
||
from pandas import ( | ||
CategoricalIndex, | ||
DataFrame, | ||
|
@@ -24,10 +22,7 @@ | |
_maybe_adjust_name, | ||
) | ||
|
||
pytestmark = [ | ||
pytest.mark.single_cpu, | ||
pytest.mark.xfail(using_string_dtype(), reason="TODO(infer_string)", strict=False), | ||
] | ||
pytestmark = [pytest.mark.single_cpu] | ||
|
||
|
||
def test_pass_spec_to_storer(setup_path): | ||
|
@@ -93,9 +88,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]\nbecause its data " | ||
"contents are not [string] but [date] object dtype" | ||
), | ||
re.escape("[date] is not implemented as a table column"), | ||
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. I think the original error message here is much clearer - is there no way to catch and raise that for the string types? 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. Not sure what you mean, this error is not raised for string types. It's being raised for date types. When |
||
] | ||
) | ||
with pytest.raises(TypeError, match=msg): | ||
store.append("df_unimplemented", df) | ||
|
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.
Would like to make sure this is correct.
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.
So the string type is just truncating the last 4 rows? Is it an invalid unicode sequence?
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.
The DataFrame is all NaN in rows 0-15 inclusive (L250 in this PR), and it is being appended to the store with
dropna=True
.