-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: ArrowDtype.construct_from_string round-trip #50689
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,13 +250,9 @@ def test_astype_str(self, data, request): | |
class TestConstructors(base.BaseConstructorsTests): | ||
def test_from_dtype(self, data, request): | ||
pa_dtype = data.dtype.pyarrow_dtype | ||
if (pa.types.is_timestamp(pa_dtype) and pa_dtype.tz) or pa.types.is_string( | ||
pa_dtype | ||
): | ||
if pa.types.is_string(pa_dtype): | ||
reason = "ArrowDtype(pa.string()) != StringDtype('pyarrow')" | ||
else: | ||
reason = f"pyarrow.type_for_alias cannot infer {pa_dtype}" | ||
|
||
if pa.types.is_string(pa_dtype): | ||
reason = "ArrowDtype(pa.string()) != StringDtype('pyarrow')" | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
reason=reason, | ||
|
@@ -604,65 +600,24 @@ def test_in_numeric_groupby(self, data_for_grouping): | |
class TestBaseDtype(base.BaseDtypeTests): | ||
def test_construct_from_string_own_name(self, dtype, request): | ||
pa_dtype = dtype.pyarrow_dtype | ||
if pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None: | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
raises=NotImplementedError, | ||
reason=f"pyarrow.type_for_alias cannot infer {pa_dtype}", | ||
) | ||
) | ||
elif pa.types.is_string(pa_dtype): | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
raises=TypeError, | ||
reason=( | ||
"Still support StringDtype('pyarrow') " | ||
"over ArrowDtype(pa.string())" | ||
), | ||
) | ||
) | ||
|
||
if pa.types.is_string(pa_dtype): | ||
# We still support StringDtype('pyarrow') over ArrowDtype(pa.string()) | ||
msg = r"string\[pyarrow\] should be constructed by StringDtype" | ||
with pytest.raises(TypeError, match=msg): | ||
dtype.construct_from_string(dtype.name) | ||
|
||
return | ||
|
||
super().test_construct_from_string_own_name(dtype) | ||
|
||
def test_is_dtype_from_name(self, dtype, request): | ||
pa_dtype = dtype.pyarrow_dtype | ||
if pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None: | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
raises=NotImplementedError, | ||
reason=f"pyarrow.type_for_alias cannot infer {pa_dtype}", | ||
) | ||
) | ||
elif pa.types.is_string(pa_dtype): | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
reason=( | ||
"Still support StringDtype('pyarrow') " | ||
"over ArrowDtype(pa.string())" | ||
), | ||
) | ||
) | ||
super().test_is_dtype_from_name(dtype) | ||
|
||
def test_construct_from_string(self, dtype, request): | ||
pa_dtype = dtype.pyarrow_dtype | ||
if pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None: | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
raises=NotImplementedError, | ||
reason=f"pyarrow.type_for_alias cannot infer {pa_dtype}", | ||
) | ||
) | ||
elif pa.types.is_string(pa_dtype): | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
raises=TypeError, | ||
reason=( | ||
"Still support StringDtype('pyarrow') " | ||
"over ArrowDtype(pa.string())" | ||
), | ||
) | ||
) | ||
super().test_construct_from_string(dtype) | ||
if pa.types.is_string(pa_dtype): | ||
# We still support StringDtype('pyarrow') over ArrowDtype(pa.string()) | ||
assert not type(dtype).is_dtype(dtype.name) | ||
else: | ||
super().test_is_dtype_from_name(dtype) | ||
|
||
def test_construct_from_string_another_type_raises(self, dtype): | ||
msg = r"'another_type' must end with '\[pyarrow\]'" | ||
|
@@ -753,13 +708,6 @@ def test_EA_types(self, engine, data, request): | |
request.node.add_marker( | ||
pytest.mark.xfail(raises=TypeError, reason="GH 47534") | ||
) | ||
elif pa.types.is_timestamp(pa_dtype) and pa_dtype.tz is not None: | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
raises=NotImplementedError, | ||
reason=f"Parameterized types with tz={pa_dtype.tz} not supported.", | ||
) | ||
) | ||
elif pa.types.is_timestamp(pa_dtype) and pa_dtype.unit in ("us", "ns"): | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
|
@@ -1266,7 +1214,12 @@ def test_invalid_other_comp(self, data, comparison_op): | |
|
||
def test_arrowdtype_construct_from_string_type_with_unsupported_parameters(): | ||
with pytest.raises(NotImplementedError, match="Passing pyarrow type"): | ||
ArrowDtype.construct_from_string("timestamp[s, tz=UTC][pyarrow]") | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ArrowDtype.construct_from_string("not_a_real_dype[s, tz=UTC][pyarrow]") | ||
|
||
# but as of GH#50689, timestamptz is supported | ||
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. In a follow up could you make this it's own test? (Nit: doesn't really fit the name of the test" 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. fair enough, will do |
||
dtype = ArrowDtype.construct_from_string("timestamp[s, tz=UTC][pyarrow]") | ||
expected = ArrowDtype(pa.timestamp("s", "UTC")) | ||
assert dtype == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.