[ 
https://issues.apache.org/jira/browse/ARROW-1743?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16248784#comment-16248784
 ] 

ASF GitHub Bot commented on ARROW-1743:
---------------------------------------

Licht-T commented on issue #1260: ARROW-1743: [Python] Avoid non-array 
writeable-flag check
URL: https://github.com/apache/arrow/pull/1260#issuecomment-343713108
 
 
   @wesm Seems no problem.
   
   ```bash
   [python] python                                                              
                                                13:39:23  ☁  
fix-non-array-writable-check ☀
   Python 2.7.10 (default, Oct 23 2015, 19:19:21)
   [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
   Type "help", "copyright", "credits" or "license" for more information.
   >>> import pandas as pd
   >>> import pyarrow as pa
   >>>
   >>>
   >>> pd.__version__
   u'0.19.2'
   >>>
   >>> df = pd.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3]})
   >>> df['a'] = df.a.astype('category')
   >>> df = df.set_index('a')
   >>>
   >>> tbl = pa.Table.from_pandas(df)
   >>> df_new = tbl.to_pandas()
   >>>
   >>> pd.factorize(df_new['b'])
   (array([0, 1, 2]), Int64Index([1, 2, 3], dtype='int64'))
   ```
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Python] Table to_pandas fails when index contains categorical column
> ---------------------------------------------------------------------
>
>                 Key: ARROW-1743
>                 URL: https://issues.apache.org/jira/browse/ARROW-1743
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>    Affects Versions: 0.7.1
>            Reporter: Brian Pendleton
>            Assignee: Licht Takeuchi
>              Labels: pull-request-available
>             Fix For: 0.8.0
>
>
> Categorical columns in the index of a dataframe are causing a roundtrip 
> failure.  
> {code}
> >>> df = pd.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3]})
> >>> df['a'] = df.a.astype('category')
> >>> df = df.set_index('a')
> >>> tbl = pa.Table.from_pandas(df)
> >>> tbl.to_pandas()
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "table.pxi", line 881, in pyarrow.lib.Table.to_pandas
>   File 
> "C:\Users\bpendlet\Miniconda3\envs\panpy3\lib\site-packages\pyarrow\pandas_compat.py",
>  line 303, in table_to_blockmanager
>     if not values.flags.writeable:
> AttributeError: 'Categorical' object has no attribute 'flags'
> {code}
> Works as expected when you don't change have the categorical:
> {code}
> >>> df = pd.DataFrame({'a': [1, 2, 3], 'b': [1, 2, 3]})
> >>> df = df.set_index('a')
> >>> tbl = pa.Table.from_pandas(df)
> >>> tbl.to_pandas()
>    b
> a
> 1  1
> 2  2
> 3  3
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to