Skip to content

Conversation

@kszucs
Copy link
Member

@kszucs kszucs commented Apr 25, 2018

No description provided.

@kszucs kszucs changed the title ARROW-2286: [Python] Allow subscripting pyarrow.lib.StructValue ARROW-2286: [C++/Python] Allow subscripting pyarrow.lib.StructValue Apr 25, 2018
@pitrou
Copy link
Member

pitrou commented Apr 25, 2018

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

@kszucs
Copy link
Member Author

kszucs commented Apr 26, 2018

@pitrou rebase done, but the builds are still failing

@pitrou
Copy link
Member

pitrou commented Apr 26, 2018

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

Copy link
Member

@pitrou pitrou left a 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).

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

int64_t GetChildIndex(const std::string& name) const;

private:
mutable std::unordered_map<std::string, int> name_to_index_;
Copy link
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?

std::shared_ptr<Field> result;

result = struct_type.GetChildByName("f1");
ASSERT_TRUE(f1->Equals(result));
Copy link
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).

ASSERT_TRUE(f3->Equals(result));

result = struct_type.GetChildByName("not-found");
ASSERT_TRUE(result == nullptr);
Copy link
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.

assert isinstance(set_from_array, set)
assert set_from_array == {1, 2}

def test_struct_array_subscripting(self):
Copy link
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.

Copy link
Member

@pitrou pitrou left a 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.

@pitrou pitrou closed this in c8a3ed8 Apr 26, 2018
Sign up for free to 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