-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-2286: [C++/Python] Allow subscripting pyarrow.lib.StructValue #1943
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
Conversation
|
Thanks @kszucs. Can you rebase to fix the CI failures? |
|
@pitrou rebase done, but the builds are still failing |
|
Ok, so the Travis-CI failure is unrelated (we are getting npm errors intermittently: see ARROW-2509). However, the Windows compile errors are probably caused by this PR. I'll point out the issue in a comment. |
| if index < 0: | ||
| raise KeyError(key) | ||
|
|
||
| return pyarrow_wrap_array(self.ap.field(index))[self.index] |
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.
You are passing an int64_t to a function that takes a (32-bit) int, hence the warning about truncation which is turned into an error.
pitrou
left a comment
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.
See my comments below about the likely cause of the Windows failure (and some more minor comments).
cpp/src/arrow/type.h
Outdated
| std::shared_ptr<Field> GetChildByName(const std::string& name) const; | ||
|
|
||
| /// Returns -1 if name not found | ||
| int64_t GetChildIndex(const std::string& name) const; |
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.
Child indices are int everywhere else, not int64_t, so this function should return int as well.
| int64_t GetChildIndex(const std::string& name) const; | ||
|
|
||
| private: | ||
| mutable std::unordered_map<std::string, int> name_to_index_; |
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.
Add a comment that this is lazily initialized?
cpp/src/arrow/type-test.cc
Outdated
| std::shared_ptr<Field> result; | ||
|
|
||
| result = struct_type.GetChildByName("f1"); | ||
| ASSERT_TRUE(f1->Equals(result)); |
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.
You could actually check for pointer equality here, i.e. ASSERT_EQ(f1, result).
cpp/src/arrow/type-test.cc
Outdated
| ASSERT_TRUE(f3->Equals(result)); | ||
|
|
||
| result = struct_type.GetChildByName("not-found"); | ||
| ASSERT_TRUE(result == nullptr); |
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.
ASSERT_EQ will produce nicer diagnostics on failure.
python/pyarrow/tests/test_scalars.py
Outdated
| assert isinstance(set_from_array, set) | ||
| assert set_from_array == {1, 2} | ||
|
|
||
| def test_struct_array_subscripting(self): |
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.
Nit: call this test_struct_value_subscripting? You're not subscripting the array here.
pitrou
left a comment
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.
Thanks @kszucs for doing this! LGTM now.
No description provided.