You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "honno (via GitHub)" <gi...@apache.org> on 2023/05/10 17:10:47 UTC

[GitHub] [arrow] honno opened a new issue, #35535: NaNs are interchanged as null

honno opened a new issue, #35535:
URL: https://github.com/apache/arrow/issues/35535

   ### Describe the bug, including details regarding any error messages, version, and platform.
   
   First of, this might not be a problem—let me know if that's the case! Hard for me to wrap my head around the consequences of Arrow's NA model with interchanging :sweat_smile:
   
   So, if one were to interchange a `pandas.DataFrame` containing NaNs to a `pyarrow.Table`, one gets nulls in place of NaNs.
   
   ```python
   >>> import pandas as pd
   >>> import numpy as np
   >>> df = pd.DataFrame({"foo": pd.Series([float("nan")], dtype=np.float64)})
   >>> from pyarrow.interchange import from_dataframe
   >>> from_dataframe(df)
   pyarrow.Table
   foo: double
   ----
   foo: [[null]    # expect NaN?
   ```
   
   We get the same with `modin`, which also adopts the interchange protocol.
   
   ```python
   >>> import modin
   >>> import ray
   >>> ray.init(local_mode=True)
   >>> from modin.config import Engine
   >>> Engine.put("ray")
   >>> from modin import pandas as mpd
   >>> df = mpd.DataFrame({"foo": mpd.Series([float("nan")], dtype=np.float64)})
   >>> from_dataframe(df)
   pyarrow.Table
   foo: double
   ----
   foo: [[null]]
   ```
   
   I see interchanging another `pa.Table` with NaNs works fine, asummedly because `from_dataframe()` short-circuits when it gets a `pa.Table`/`pa.RecordBatch`.
   
   ```python
   >>> table = pa.Table.from_pydict({"foo": pa.array([float("nan")], type=pa.float64())})
   >>> from_dataframe(table)
   pyarrow.Table
   foo: double
   ----
   foo: [[nan]]
   ```
   
   Using the arrow nightly from https://pypi.fury.io/arrow-nightlies/
   
   cc @AlenkaF
   
   
   
   ### 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


[GitHub] [arrow] jorisvandenbossche commented on issue #35535: NaNs are interchanged as null

Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche commented on issue #35535:
URL: https://github.com/apache/arrow/issues/35535#issuecomment-1543482341

   > So, if one were to interchange a `pandas.DataFrame` containing NaNs to a `pyarrow.Table`, one gets nulls in place of NaNs.
   
   AFAIK this is expected, because pandas creates an interchange object explicitly indicating that the NaN is used as the null value:
   
   ```
   In [15]: df.__dataframe__().get_column_by_name("foo").describe_null
   Out[15]: (<ColumnNullType.USE_NAN: 1>, None)
   ```
   
   And thus pyarrow correctly converts this to null on the Arrow side. 
   
   
   
   > I see interchanging another `pa.Table` with NaNs works fine, asummedly because `from_dataframe()` short-circuits when it gets a `pa.Table`/`pa.RecordBatch`.
   
   We are indeed short-cutting here. But even when not doing that (by explicitly using the lower level function that doesn't have this short-circuit), we preserve NaNs:
   
   ```
   In [22]: from pyarrow.interchange.from_dataframe import _from_dataframe
   
   In [23]: _from_dataframe(table.__dataframe__())
   Out[23]: 
   pyarrow.Table
   foo: double
   ----
   foo: [[nan]]
   ```
   
   That's because pyarrow does _not_ set that the NaN is the missing value indicator, and thus NaNs in the input are preserved.
   
   


-- 
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