You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python] Cannot create RecordBatch with nested struct containing extension type #33059
So what is missing here is the automatic cast from the storage type to the extension type. This is currently being tackled in #14106 (ARROW-14500).
Testing your example with the branch of #14106, it works for me (with one caveat that you need to register the extension types (eg pa.register_extension_type(subnet_type)) to preserve them in an IPC roundtrip.
Would you mind pointing me to instructions on how to do the test that you performed? I am using Poetry and couldn't get the branch to compile. In theory, I thought this should do the trick:
But this fails to compile due to missing dependencies. (I managed to workaround OpenSSL by providing the right env var, but now I'm stuck with Flight not being found.) I was hoping that there is some sort of dev guide that shows how to get going.
Matthias Vallentin / @mavam:
Since I didn't manage (yet) to try out the branch under development, I have one other issue, per the attached example. In this case I'm getting:
I'm not sure whether that's considered a "cast" internally or whether I'm simply not creating an ExtensionArray properly from a dictionary. Any guidance would be much appreciated.
Would you mind pointing me to instructions on how to do the test that you performed? I am using Poetry and couldn't get the branch to compile. In theory, I thought this should do the trick:
Since I didn't manage (yet) to try out the branch under development, I have one other issue, per the attached example. In this case I'm getting:
There is a small difference between the types. Your extension type is defined with a dictionary of uint8 indices, while the dictionary array you have as int8 indices (uint8 vs int8). At the moment this needs to be exactly the same, but so the referenced PR should also allow casting from dictionary to extension<dictionary>.
Regarding the dictionary, nowhere in the code I use {}int8{}. Where do I implicitly "commit" to int8 without knowing it?
EDIT: I think I found the issue. Going through pa.array(..., type=dictionary_type) is not creating indices of the type as given by {}dictionary_type{}. I had to go through pa.DictionaryArray.from_arrays with explicitly typed arrays. (The detail fix is here: https://github.com/tenzir/vast/pull/2606/files)
Converting to dictionary array will promote to a wider integer type for
indices if the number of distinct values cannot be represented, even if
the index type was explicitly set. This means that if there are more than
127 values the returned dictionary array's index type will be at least
pa.int16() even if pa.int8() was passed to the function. Note that an
explicit index type will not be demoted even if it is wider than required.
but I am not sure uint being promoted to int of same size fits here as this change seems to happen even if not necessary. I asked Copilot to help me dig through the code. I seems this is expected on the C++ side, see:
DictionaryBuilder uses AdaptiveIntBuilder to create indices and it does not utilize AdaptiveUIntBuilder. Looking at the format docs, I also found:
Since unsigned integers can be more difficult to work with in some cases (e.g. in the JVM), we recommend preferring signed integers over unsigned integers for representing dictionary indices.
Activity
asfimport commentedon Sep 27, 2022
Joris Van den Bossche / @jorisvandenbossche:
@mavam Thanks for the report and the nice example!
So what is missing here is the automatic cast from the storage type to the extension type. This is currently being tackled in #14106 (ARROW-14500).
Testing your example with the branch of #14106, it works for me (with one caveat that you need to register the extension types (eg
pa.register_extension_type(subnet_type)) to preserve them in an IPC roundtrip.asfimport commentedon Sep 29, 2022
Matthias Vallentin / @mavam:
Thanks for the point, @jorisvandenbossche. Glad to see that a fix is underway.
Would you mind pointing me to instructions on how to do the test that you performed? I am using Poetry and couldn't get the branch to compile. In theory, I thought this should do the trick:
But this fails to compile due to missing dependencies. (I managed to workaround OpenSSL by providing the right env var, but now I'm stuck with Flight not being found.) I was hoping that there is some sort of dev guide that shows how to get going.
asfimport commentedon Sep 29, 2022
Matthias Vallentin / @mavam:
Since I didn't manage (yet) to try out the branch under development, I have one other issue, per the attached example. In this case I'm getting:
I'm not sure whether that's considered a "cast" internally or whether I'm simply not creating an
ExtensionArrayproperly from a dictionary. Any guidance would be much appreciated.enum.py
asfimport commentedon Sep 30, 2022
Joris Van den Bossche / @jorisvandenbossche:
Since it is not yet merged, you would have to install pyarrow from source, and thus also build Arrow C++ from source, which won't be possible with just poetry (see https://arrow.apache.org/docs/dev/developers/guide/step_by_step/building.html and https://arrow.apache.org/docs/dev/developers/python.html).
We do have nightly packages, but so for that you will have to wait until it is merged.
asfimport commentedon Sep 30, 2022
Joris Van den Bossche / @jorisvandenbossche:
There is a small difference between the types. Your extension type is defined with a dictionary of uint8 indices, while the dictionary array you have as int8 indices (uint8 vs int8). At the moment this needs to be exactly the same, but so the referenced PR should also allow casting from dictionary to extension<dictionary>.
asfimport commentedon Oct 1, 2022
Matthias Vallentin / @mavam:
Thanks for the guidance, Joris!
Regarding the dictionary, nowhere in the code I use
{}int8{}. Where do I implicitly "commit" toint8without knowing it?EDIT: I think I found the issue. Going through
pa.array(..., type=dictionary_type)is not creating indices of the type as given by{}dictionary_type{}. I had to go throughpa.DictionaryArray.from_arrayswith explicitly typed arrays. (The detail fix is here: https://github.com/tenzir/vast/pull/2606/files)asfimport commentedon Oct 4, 2022
Joris Van den Bossche / @jorisvandenbossche:
That would be a bug IMO, but I can't directly reproduce this. In the below example, I specify int8, and it does return a dictionary type using int8:
asfimport commentedon Oct 17, 2022
Matthias Vallentin / @mavam:
Can you try any other type than
{}int8{}? For example,uint8fails for me:asfimport commentedon Dec 14, 2022
Matthias Vallentin / @mavam:
@jorisvandenbossche mind taking a look at this? This still fails for current pyarrow.
assignUser commentedon Jan 11, 2023
Not a blocker, please re-add if you disagree @jorisvandenbossche
AlenkaF commentedon May 6, 2026
I will close this issue as it has been fixed by #14106.
As for the promoting of integer types for indices in case of the dictionary type, there is a comment connected to this in the docstrings:
arrow/python/pyarrow/array.pxi
Lines 188 to 193 in 23cd1ff
but I am not sure
uintbeing promoted tointof same size fits here as this change seems to happen even if not necessary. I asked Copilot to help me dig through the code. I seems this is expected on the C++ side, see:arrow/cpp/src/arrow/array/builder_dict.h
Lines 671 to 674 in 61c96ca
DictionaryBuilderusesAdaptiveIntBuilderto create indices and it does not utilizeAdaptiveUIntBuilder. Looking at the format docs, I also found:here: https://arrow.apache.org/docs/format/Columnar.html#dictionary-encoded-layout
A separate issue can be opened in case this design decision needs to be discussed further.