-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-7858: [C++][Python] Support casting from ExtensionArray #6633
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 all commits
6891ba8
8473b24
600d7b0
ec0c425
26750be
bfdde93
957f191
fcde06d
e03c83f
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 |
|---|---|---|
|
|
@@ -382,11 +382,7 @@ void SleepFor(double seconds) { | |
| // Extension types | ||
|
|
||
| bool UUIDType::ExtensionEquals(const ExtensionType& other) const { | ||
| const auto& other_ext = static_cast<const ExtensionType&>(other); | ||
| if (other_ext.extension_name() != this->extension_name()) { | ||
| return false; | ||
| } | ||
| return true; | ||
| return (other.extension_name() == this->extension_name()); | ||
| } | ||
|
Member
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 wonder if this should be the default implementation of
Member
Author
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. The name and the storage type should be equal, created a follow-up JIRA https://issues.apache.org/jira/browse/ARROW-8143 |
||
|
|
||
| std::shared_ptr<Array> UUIDType::MakeArray(std::shared_ptr<ArrayData> data) const { | ||
|
|
@@ -423,4 +419,38 @@ std::shared_ptr<Array> ExampleUUID() { | |
| return MakeArray(ext_data); | ||
| } | ||
|
|
||
| bool SmallintType::ExtensionEquals(const ExtensionType& other) const { | ||
| return (other.extension_name() == this->extension_name()); | ||
| } | ||
|
|
||
| std::shared_ptr<Array> SmallintType::MakeArray(std::shared_ptr<ArrayData> data) const { | ||
| DCHECK_EQ(data->type->id(), Type::EXTENSION); | ||
| DCHECK_EQ("smallint", static_cast<const ExtensionType&>(*data->type).extension_name()); | ||
| return std::make_shared<SmallintArray>(data); | ||
| } | ||
|
|
||
| Status SmallintType::Deserialize(std::shared_ptr<DataType> storage_type, | ||
| const std::string& serialized, | ||
| std::shared_ptr<DataType>* out) const { | ||
| if (serialized != "smallint") { | ||
| return Status::Invalid("Type identifier did not match"); | ||
| } | ||
| if (!storage_type->Equals(*int16())) { | ||
| return Status::Invalid("Invalid storage type for SmallintType"); | ||
| } | ||
| *out = std::make_shared<SmallintType>(); | ||
| return Status::OK(); | ||
| } | ||
|
|
||
| std::shared_ptr<DataType> smallint() { return std::make_shared<SmallintType>(); } | ||
|
|
||
| std::shared_ptr<Array> ExampleSmallint() { | ||
| auto storage_type = int16(); | ||
| auto ext_type = smallint(); | ||
| auto arr = ArrayFromJSON(storage_type, "[-32768, null, 1, 2, 3, 4, 32767]"); | ||
| auto ext_data = arr->data()->Copy(); | ||
| ext_data->type = ext_type; | ||
| return MakeArray(ext_data); | ||
| } | ||
|
|
||
| } // namespace arrow | ||
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.
Does it allocate if the out_type and storage_type are the same?
Uh oh!
There was an error while loading. Please reload this page.
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.
Added tests on both C++ and Python side, seems like no allocation happens.