-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: is_dtype_equal(dtype, "string[pyarrow]") raises if pyarrow not installed #44327
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
Changes from 9 commits
542032c
76ab6fa
c82d836
c35e162
cff657a
dce9db6
5abfa2e
fb0bd2a
f7b8888
2de4936
66327e7
9566360
0f35541
7ea6b15
9b0dc6c
b0a75fc
75a4b26
f5bedc6
9c68f5c
c550a00
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 |
---|---|---|
|
@@ -599,9 +599,12 @@ def is_dtype_equal(source, target) -> bool: | |
if not isinstance(source, str): | ||
# GH#38516 ensure we get the same behavior from | ||
# is_dtype_equal(CDT, "category") and CDT == "category" | ||
# GH-44276 ensures behaviour is consistent | ||
# is_dtype_equal (dtype, "string[pyarrow]") | ||
try: | ||
src = get_dtype(source) | ||
if isinstance(src, ExtensionDtype): | ||
if isinstance(src, (ExtensionDtype, np.dtype)): | ||
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. is this change still needed? 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. It is needed because dtypes such as 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.
It is not needed if we catch ImportError more generally, I think; I pushed some small commits to verify this. |
||
|
||
return src == target | ||
except (TypeError, AttributeError): | ||
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 you can probably catch the ImportError here (so it always returns False if the above raises an ImportError) 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. Done |
||
return False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,11 @@ def test_construction_from_string(self, dtype): | |
with pytest.raises(TypeError, match=msg): | ||
CategoricalDtype.construct_from_string("foo") | ||
|
||
@pytest.importorskip("pyarrow") | ||
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 don't think this test should be skipped if pyarrow is not installed? Because I understood the issue that checking the dtype equality currently raises if pyarrow is not installed, while it should return False instead. So both if pyarrow is installed or not, this test should pass and I think you can simply remove the decorator. 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. Done |
||
def test_pyarrow_string_import_error(self, dtype): | ||
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. Another note: this test is added to 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. Request you to inform me where do I exactly put the test, in which file and which function 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. You can put it in 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. Done |
||
# GH-44276 | ||
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. can you flesh this out a tiny bit e.g. 'dont raise if pyarrow is not installed' 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. Done |
||
assert not is_dtype_equal(dtype, "string[pyarrow]") | ||
|
||
def test_constructor_invalid(self): | ||
msg = "Parameter 'categories' must be list-like" | ||
with pytest.raises(TypeError, match=msg): | ||
|
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 won't render & is not public facing anyhow. remove the note
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 did not understand the part where "is not public facing anyhow.". I will anyhow remove 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.
Do I remove this?
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 you can keep it, but reword it a bit to not mention
is_dtype_equal
explicitly. Something like "Fixed a bug in checking if a dtype is thestring[pyarrow]
dtype incorrectly raising an error when pyarrow is not installed (:issue:...)"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.
Done