You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "adriangb (via GitHub)" <gi...@apache.org> on 2023/11/30 19:36:51 UTC
[I] to_pylist incorrectly converts map to list of tuples [arrow]
adriangb opened a new issue, #39010:
URL: https://github.com/apache/arrow/issues/39010
### Describe the bug, including details regarding any error messages, version, and platform.
```python
import pyarrow as pa
schema = pa.schema([pa.field('x', pa.map_(pa.string(), pa.int64()))])
data = [{'x': {'a': 1}}]
pa.RecordBatch.from_pylist(data, schema=schema).to_pylist()
# [{'x': [('a', 1)]}]
```
I understand that this may be how it's stored internally but I feel like it should be converted to a dict.
Using `struct` is not an option because my keys are not fixed.
### Component(s)
Python
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Support converting map to dict (instead of list of tuples) in scalar conversion / to_pylist [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou closed issue #39010: [Python] Support converting map to dict (instead of list of tuples) in scalar conversion / to_pylist
URL: https://github.com/apache/arrow/issues/39010
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Support converting map to dict (instead of list of tuples) in scalar conversion / to_pylist [arrow]
Posted by "jonded94 (via GitHub)" <gi...@apache.org>.
jonded94 commented on issue #39010:
URL: https://github.com/apache/arrow/issues/39010#issuecomment-2643067063
Hey @jorisvandenbossche, I attached some Draft PR that would already fix the problem which fundamentally blocks us right now. We never would want `MapScalar` to be deserialized to these `(key, value)` tuples.
I know that this is far from merge ready, but is there some way to *quickly* get at least the builds in the CI to work? It would really massively help up if we already had some Linux (x86/ARM) + MacOS (ARM) wheels, since the build process seems to be quite involved to reproduce.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Support converting map to dict (instead of list of tuples) in scalar conversion / to_pylist [arrow]
Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on issue #39010:
URL: https://github.com/apache/arrow/issues/39010#issuecomment-1836098305
Makes sense!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Support converting map to dict (instead of list of tuples) in scalar conversion / to_pylist [arrow]
Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on issue #39010:
URL: https://github.com/apache/arrow/issues/39010#issuecomment-2671810158
Issue resolved by pull request 45471
https://github.com/apache/arrow/pull/45471
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] to_pylist incorrectly converts map to list of tuples [arrow]
Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche commented on issue #39010:
URL: https://github.com/apache/arrow/issues/39010#issuecomment-1835649581
The reason that a list of tuples was used as default in the past is that a dict cannot always represent the data of a map array, because a map allows duplicate keys.
But of course very often that is not an issue and you want dicts. And therefore a new keyword `maps_as_pydicts` was recently added (https://github.com/apache/arrow/pull/34730), but only to the conversion path to pandas.
Using your example:
```python
schema = pa.schema([pa.field('x', pa.map_(pa.string(), pa.int64()))])
data = [{'x': {'a': 1}}]
batch = pa.RecordBatch.from_pylist(data, schema=schema)
```
this can now be converted to a pandas DataFrame (or numpy array) using dicts:
```
In [8]: batch.to_pandas(maps_as_pydicts="strict")
Out[8]:
x
0 {'a': 1}
```
However, the `to_pylist()` method takes a different code path, where this is not yet supported. Under the hood, this just calls `as_py()` on the individual MapScalar objects in a for loop.
But I think it certainly make sense to add this same keyword to this scalar conversion code path as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Python] Support converting map to dict (instead of list of tuples) in scalar conversion / to_pylist [arrow]
Posted by "jonded94 (via GitHub)" <gi...@apache.org>.
jonded94 commented on issue #39010:
URL: https://github.com/apache/arrow/issues/39010#issuecomment-2639752703
Hey, we recently invested much time switching to parquet in our internal data processing tooling and stumbled over this exact issue. This is somewhat bad for us since we try to use parquet and pyarrow natively as much as possible, and then this workaround through pandas is a bit silly and also not optimal from a performance point of view.
Is there any traction currently around adding such a `maps_as_pydicts` parameter to `to_pylist`? Can one support in any way? Do you think this would be much work?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org