Skip to content

ARROW-2286: [C++/Python] Allow subscripting pyarrow.lib.StructValue - #1943

Closed
kszucs wants to merge 4 commits into
apache:masterfrom
kszucs:ARROW-2286
Closed

ARROW-2286: [C++/Python] Allow subscripting pyarrow.lib.StructValue#1943
kszucs wants to merge 4 commits into
apache:masterfrom
kszucs:ARROW-2286

Conversation

@kszucs

Copy link
Copy Markdown
Member

No description provided.

@kszucskszucs changed the title ARROW-2286: [Python] Allow subscripting pyarrow.lib.StructValueARROW-2286: [C++/Python] Allow subscripting pyarrow.lib.StructValueApr 25, 2018
@pitrou

Copy link
Copy Markdown
Member

Thanks @kszucs. Can you rebase to fix the CI failures?

@kszucs

Copy link
Copy Markdown
MemberAuthor

@pitrou rebase done, but the builds are still failing

@pitrou

Copy link
Copy Markdown
Member

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]

Copy link
Copy Markdown
Member

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.

@pitroupitrou left a comment

Copy link
Copy Markdown
Member

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).

Comment threadcpp/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;

Copy link
Copy Markdown
Member

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.

Comment threadcpp/src/arrow/type.h
int64_t GetChildIndex(const std::string& name) const;

private:
mutable std::unordered_map<std::string, int> name_to_index_;

Copy link
Copy Markdown
Member

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?

Comment threadcpp/src/arrow/type-test.cc Outdated
std::shared_ptr<Field> result;

result = struct_type.GetChildByName("f1");
ASSERT_TRUE(f1->Equals(result));

Copy link
Copy Markdown
Member

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).

Comment threadcpp/src/arrow/type-test.cc Outdated
ASSERT_TRUE(f3->Equals(result));

result = struct_type.GetChildByName("not-found");
ASSERT_TRUE(result == nullptr);

Copy link
Copy Markdown
Member

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.

Comment threadpython/pyarrow/tests/test_scalars.py Outdated
assert isinstance(set_from_array, set)
assert set_from_array == {1, 2}

def test_struct_array_subscripting(self):

Copy link
Copy Markdown
Member

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.

@pitroupitrou left a comment

Copy link
Copy Markdown
Member

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.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@kszucs@pitrou