-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
Conversation
if using_infer_string: | ||
# TODO: Test is incorrect when not using_infer_string. | ||
# Should take the last 4 rows uncondiationally. | ||
expected = expected[16:] |
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
.
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 this is currently a bug then? (that indirectly gets fixed somehow by the presence of a string dtype? do you know if this also happens if there is no string column?)
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.
@jorisvandenbossche - the cases in this test above show that when dropna=True, the NA rows are dropped for e.g. floats.
I missed L239:
# nan some entire rows (string are still written!)
This goes back to #3013. I am wondering if at one point the line df.ix[0:15,:] = np.nan
did not put the NaNs in string columns, in which case it makes sense to not drop these rows?
In any case, the behavior for string dtype is now working equivalently to other dtypes.
…xfail_pytable_misc
if using_infer_string: | ||
# TODO: Test is incorrect when not using_infer_string. | ||
# Should take the last 4 rows uncondiationally. | ||
expected = expected[16:] |
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?
@@ -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 comment
The 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 comment
The 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.
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.
This error message got changed in #60829; we no longer report on the shape.
"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 comment
The 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 comment
The 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 infer_string=False
, this function is passed a single object block with a mix of strings and dates. In this case, the data of the block is inferred as mixed, and then checked column-by-column. This is where the top message (which I think is confusing) is raised. When infer_string=True
, each string array is fed into this function individually and does not raise. Then the object block is fed in containing only dates. This is inferred as dates, and the corresponding error message is raised.
@WillAyd - friendly ping |
@pytest.mark.xfail( | ||
using_string_dtype() and has_pyarrow, | ||
reason="TODO(infer_string): can't encode '\ud800': surrogates not allowed", | ||
) |
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.
Do you know if the error happens when writing or reading? (I suppose reading because even if it was object dtype we try to read it as strings?)
This is probably not something we can fix? Wondering (not for this PR) if we should fall back to object dtype in such a case (or at least give that option), so the user can still load the data and inspect it.
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.
I hadn't looked into this one - currently it raises on data creation. Fixing that by specifying object dtype, you're right it's the reading that raises here. The error happens in Series.str.decode(encoding, errors=errors)
. I am wondering if we should add a dtype
argument to decode
so that you can force object dtype - that seems generally useful to alleviate this pain-point, and then we could use it to provide a fallback in pytables.
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.
PyArrow strings not supporting surrogates is another interesting case in regards to PDEP-13. #58455
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.
I am wondering if we should add a
dtype
argument todecode
so that you can force object dtype - that seems generally useful to alleviate this pain-point, and then we could use it to provide a fallback in pytables.
+1
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.
I listed this issue in #59328 as one of the breaking changes when users upgrade to the string dtype (in this case at least when using pyarrow).
But so we should also list this as one of the differences between the pyarrow and python engines.
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.
I do wonder if we should start nudging users down the path of referring to our strings as utf8. For other encodings, the binary type is the best bet for now, and probably for a while (I'm not aware of any non-utf8 Arrow array work, but maybe its out there)
Great work thanks @rhshadrach |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
@meeseeksdev backport to 2.3.x |
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulations — you did some good work! Hopefully your backport PR will be tested by the continuous integration and merged soon! Remember to remove the If these instructions are inaccurate, feel free to suggest an improvement. |
(cherry picked from commit 4511251)
Backport PR: #60916 |
…0916) * ENH: Improved error message and raise new error for small-string NaN edge case in HDFStore.append (#60829) * Add clearer error messages for datatype mismatch in HDFStore.append. Raise ValueError when nan_rep too large for pytable column. Add and modify applicable test code. * Fix missed tests and correct mistake in error message. * Remove excess comments. Reverse error type change to avoid api changes. Move nan_rep tests into separate function. (cherry picked from commit 57340ec) * TST(string dtype): Resolve xfails in pytables (#60795) (cherry picked from commit 4511251) * Adjust test --------- Co-authored-by: Jake Thomas Trevallion <[email protected]>
…ading with condition (#60967) * ENH: Improved error message and raise new error for small-string NaN edge case in HDFStore.append (#60829) * Add clearer error messages for datatype mismatch in HDFStore.append. Raise ValueError when nan_rep too large for pytable column. Add and modify applicable test code. * Fix missed tests and correct mistake in error message. * Remove excess comments. Reverse error type change to avoid api changes. Move nan_rep tests into separate function. (cherry picked from commit 57340ec) * TST(string dtype): Resolve xfails in pytables (#60795) (cherry picked from commit 4511251) * BUG(string dtype): Resolve pytables xfail when reading with condition (#60943) (cherry picked from commit 0ec5f26) --------- Co-authored-by: Jake Thomas Trevallion <[email protected]>
* ENH: Improved error message and raise new error for small-string NaN edge case in HDFStore.append (#60829) * Add clearer error messages for datatype mismatch in HDFStore.append. Raise ValueError when nan_rep too large for pytable column. Add and modify applicable test code. * Fix missed tests and correct mistake in error message. * Remove excess comments. Reverse error type change to avoid api changes. Move nan_rep tests into separate function. (cherry picked from commit 57340ec) * TST(string dtype): Resolve xfails in pytables (#60795) (cherry picked from commit 4511251) * BUG(string dtype): Resolve pytables xfail when reading with condition (#60943) (cherry picked from commit 0ec5f26) * Backport PR #60940: ENH: Add dtype argument to str.decode --------- Co-authored-by: Jake Thomas Trevallion <[email protected]>
…cked strings (#60984) * ENH: Improved error message and raise new error for small-string NaN edge case in HDFStore.append (#60829) * Add clearer error messages for datatype mismatch in HDFStore.append. Raise ValueError when nan_rep too large for pytable column. Add and modify applicable test code. * Fix missed tests and correct mistake in error message. * Remove excess comments. Reverse error type change to avoid api changes. Move nan_rep tests into separate function. (cherry picked from commit 57340ec) * TST(string dtype): Resolve xfails in pytables (#60795) (cherry picked from commit 4511251) * BUG(string dtype): Resolve pytables xfail when reading with condition (#60943) (cherry picked from commit 0ec5f26) * Backport PR #60940: ENH: Add dtype argument to str.decode * Backport PR #60938: ENH(string dtype): Implement cumsum for Python-backed strings --------- Co-authored-by: Jake Thomas Trevallion <[email protected]>
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.Looks like using
where
that results in empty will still give object dtype. xfailing those tests here and plan to tackle in a followup.