Uh oh!
There was an error while loading. Please reload this page.
ARROW-15545: [Python][C++] Support casting to extension type - #14106
ARROW-15545: [Python][C++] Support casting to extension type#14106jorisvandenbossche merged 27 commits into
Conversation
jorisvandenbossche
commented
Sep 13, 2022
I think ideally we handle this on the C++ side, so that it for example also works within a Acero query / dataset scan. |
rok
commented
Sep 13, 2022
This would indeed be useful in c++ too. Reading scalar_cast_numeric.cc and scalar_cast_test.cc might be a good way to get familiar with casting there. |
Thanks @rok, just saw your comment, I'll take a deeper look at that. Now in b9d8cb6 I loop over id or storage id. This creates the same result as the Python casting in e4db00b which fixes the reported issue (dictionary casting ends up as the ExtensionArray UuidType). However, when casting the test's |
rok
commented
Sep 13, 2022
@milesgranger My guess is you will want to instantiate an |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
milesgranger
commented
Sep 19, 2022
@pitrou (and others already subscribed), this is ready for a look now. Couple things I'm not sure about is if I'm adding the supported types in |
pitrou
left a comment
There was a problem hiding this comment.
Thanks @milesgranger . Some comments below.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
pitrou
commented
Sep 19, 2022
Also cc @lidavidm for potential opinions. |
lidavidm
left a comment
There was a problem hiding this comment.
Don't think I have much to add to Antoine's comments here.
It may be good to add an entry to "Generic conversions" in the docs: https://github.com/apache/arrow/blob/master/docs/source/cpp/compute.rst#conversions
Uh oh!
There was an error while loading. Please reload this page.
[skip ci] Co-authored-by: Antoine Pitrou <pitrou@free.fr>
Uh oh!
There was an error while loading. Please reload this page.
lidavidm
commented
Sep 27, 2022
Cast-to-string is how things like the CSV writer work, right? So maybe the use case isn't all that limited? |
mavam
commented
Sep 29, 2022
Glad to see this being worked on! I'm currently running in the not-yet-implemented error, per https://issues.apache.org/jira/browse/ARROW-17839, where I have a nested struct with an extension type. |
There was a problem hiding this comment.
My interpretation was to (for now) disallow any cast unless the input array has exactly a type equal to the target storage type (in which case basically no actual cast is needed, only the creation of the extension array ..)
So something like if (!array->type()->Equals(out_ty)) { ...
(the error message you now wrote would cover that as well)
There was a problem hiding this comment.
Ah okay.. then it's updated, and also does not cast unless it's needed.
There was a problem hiding this comment.
For future reference, Miles and I chatted about this and were thinking to keep the above, and thus only disallow Extension->Extension casts for now in this PR, while still allow Any->Extension casts based on the storage type casting rules (so if Any can be cast to storage type, then it can also be cast to the Extension type).
This would make it consistent with the existing Extension->Any cast, which also just defers to the casting rules of the storage type at the moment (and does not limit to strictly casting Extension only to the exact storage type). And I think this is also what others were OK with (based on the inline discussion in #14106 (comment))
Personally I still think it's a bit inconsistent to allow casting any unrelated type to ExtensionType, but not allow an unrelated extension array to ExtensionType. But we can see to allow registering such casts in the follow-up https://issues.apache.org/jira/browse/ARROW-17890
There was a problem hiding this comment.
Implicit conversions always have to end up inconsistent in practice, so this is not a problem.
For example, in Python you can convert a dict to bool, a bool to float, but not a dict to float.
There was a problem hiding this comment.
Yes, but you can use that analogy for the "any -> extension" casts as well (for the case where "any" is not equal to "storage"), that the user needs to do "any -> storage -> extension" explicitly instead .
There was a problem hiding this comment.
Yes, but you can use that analogy for the "any -> extension" casts as well (for the case where "any" is not equal to "storage"), that the user needs to do "any -> storage -> extension" explicitly instead .
Well, I wouldn't mind this :-)
Uh oh!
There was an error while loading. Please reload this page.
jorisvandenbossche
commented
Sep 29, 2022
I opened a follow-up JIRA about allowing more casts / ability to register casts -> https://issues.apache.org/jira/browse/ARROW-17890 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
milesgranger
commented
Oct 7, 2022
Is there anything else we ought to address? |
jorisvandenbossche
left a comment
There was a problem hiding this comment.
Thanks for the last updates @milesgranger !
Planning to merge this later today (the failures seem unrelated)
jorisvandenbossche
commented
Oct 11, 2022
Thanks @milesgranger ! |
ursabot
commented
Oct 11, 2022
Benchmark runs are scheduled for baseline = 5fb02bd and contender = 06c99f7. 06c99f7 is a master commit associated with this PR. Results will be available as each benchmark for each run completes. |
ursabot
commented
Oct 11, 2022
['Python', 'R'] benchmarks have high level of regressions. |
jorisvandenbossche
commented
Oct 12, 2022
FWIW the regressions all seems to be flaky runs (they didn't continue to be slower on the subsequent merged commits) |
Fixes ARROW-15545, fixes ARROW-14500