jorisvandenbossche commented on code in PR #14080:
URL: https://github.com/apache/arrow/pull/14080#discussion_r970732387


##########
python/pyarrow/pandas_compat.py:
##########
@@ -541,7 +541,7 @@ def dataframe_to_types(df, preserve_index, columns=None):
         if _pandas_api.is_categorical(values):
             type_ = pa.array(c, from_pandas=True).type
         elif _pandas_api.is_extension_array_dtype(values):
-            type_ = pa.array(c.head(0), from_pandas=True).type
+            type_ = pa.array(c[:0], from_pandas=True).type

Review Comment:
   So for the case that `c` is a Series and not Index, this [:0] currently is 
always positional (so that's fine). But to be sure I was just checking on 
pandas main, and this now gives a warning that this will change in the future:
   
   ```
   In [9]: s = pd.Series([1, 2], index=[1, 2])
   
   In [10]: s[:0]
   <ipython-input-10-48e1b387a0b4>:1: FutureWarning: The behavior of 
`series[i:j]` with an integer-dtype index is deprecated. In a future version, 
this will be treated as *label-based* indexing, consistent with e.g. 
`series[i]` lookups. To retain the old behavior, use `series.iloc[i:j]`. To get 
the future behavior, use `series.loc[i:j]`.
     s[:0]
   Out[10]: Series([], dtype: int64)
   ```
   
   So we should avoid running into this warning. 
   
   I am thinking that we could maybe also use `values[:0]` instead? 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to