You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "izveigor (via GitHub)" <gi...@apache.org> on 2023/06/06 13:24:48 UTC

[GitHub] [arrow] izveigor opened a new pull request, #35944: MINOR: [Python] Support halffloat for Arrow list to pandas

izveigor opened a new pull request, #35944:
URL: https://github.com/apache/arrow/pull/35944

   <!--
   Thanks for opening a pull request!
   If this is your first pull request you can find detailed information on how 
   to contribute here:
     * [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   
   If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
   
   Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
   
   Then could you also rename the pull request title in the following format?
   
       GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   or
   
       MINOR: [${COMPONENT}] ${SUMMARY}
   
   In the case of PARQUET issues on JIRA the title also supports:
   
       PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
   
   -->
   
   ### Rationale for this change
   When we translate `float16` from `pyarrow` to `pandas`, no error occurs:
   ```
   >>> df = pd.DataFrame({"a": [np.float16(1), np.float16(2), np.float16(3)]})
   >>> table = pa.Table.from_pandas(df)
   >>> df_new = table.to_pandas()
   ```
   But, when we use list:
   ```
   >>> df = pd.DataFrame({"a": [[np.float16(1)], [np.float16(2)], [np.float16(3)]]})
   >>> table = pa.Table.from_pandas(df)
   >>> df_new = table.to_pandas()
   pyarrow.lib.ArrowNotImplementedError: Not implemented type for Arrow list to pandas: halffloat
   ```
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ### What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ### Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ### Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
   -->
   <!-- **This PR includes breaking changes to public APIs.** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   <!-- **This PR contains a "Critical Fix".** -->


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


[GitHub] [arrow] jorisvandenbossche merged pull request #35944: GH-36168: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche merged PR #35944:
URL: https://github.com/apache/arrow/pull/35944


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


[GitHub] [arrow] github-actions[bot] commented on pull request #35944: GH-36168: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35944:
URL: https://github.com/apache/arrow/pull/35944#issuecomment-1597601736

   :warning: GitHub issue #36168 **has been automatically assigned in GitHub** to PR creator.


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


[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #35944: GH-36168: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche commented on code in PR #35944:
URL: https://github.com/apache/arrow/pull/35944#discussion_r1244960708


##########
python/pyarrow/tests/test_array.py:
##########
@@ -3347,6 +3347,15 @@ def test_to_pandas_timezone():
     assert s.dt.tz is not None
 
 
+@pytest.mark.pandas
+def test_to_pandas_float16_list():
+    # https://github.com/apache/arrow/issues/36168
+    expected = [[np.float16(1)], [np.float16(2)], [np.float16(3)]]
+    arr = pa.array(expected)
+    result = arr.to_pandas()
+    assert result.tolist() == expected

Review Comment:
   Small comment: this conversion to list and comparing list equality doesn't actually check that the correct dtype was created (the individual elements are still equal, even when they would for example be float16 vs float32), so maybe we can still check the actual dtype, something like `result[0].dtype == "float16"`



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


[GitHub] [arrow] izveigor commented on a diff in pull request #35944: GH-36168: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "izveigor (via GitHub)" <gi...@apache.org>.
izveigor commented on code in PR #35944:
URL: https://github.com/apache/arrow/pull/35944#discussion_r1245416463


##########
python/pyarrow/tests/test_array.py:
##########
@@ -3347,6 +3347,15 @@ def test_to_pandas_timezone():
     assert s.dt.tz is not None
 
 
+@pytest.mark.pandas
+def test_to_pandas_float16_list():
+    # https://github.com/apache/arrow/issues/36168
+    expected = [[np.float16(1)], [np.float16(2)], [np.float16(3)]]
+    arr = pa.array(expected)
+    result = arr.to_pandas()
+    assert result.tolist() == expected

Review Comment:
   👌



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


[GitHub] [arrow] izveigor commented on pull request #35944: MINOR: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "izveigor (via GitHub)" <gi...@apache.org>.
izveigor commented on PR #35944:
URL: https://github.com/apache/arrow/pull/35944#issuecomment-1595053762

   @pitrou @westonpace @AlenkaF What do you think of this bug?


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


[GitHub] [arrow] AlenkaF commented on pull request #35944: MINOR: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on PR #35944:
URL: https://github.com/apache/arrow/pull/35944#issuecomment-1596463681

   Thanks for the ping @izveigor!
   Can we add the tests to the python side? Also, I think this would then need an issue opened and linked.


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


[GitHub] [arrow] izveigor commented on pull request #35944: GH-36168: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "izveigor (via GitHub)" <gi...@apache.org>.
izveigor commented on PR #35944:
URL: https://github.com/apache/arrow/pull/35944#issuecomment-1610054891

   What about this PR @AlenkaF?


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


[GitHub] [arrow] jorisvandenbossche commented on a diff in pull request #35944: GH-36168: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche commented on code in PR #35944:
URL: https://github.com/apache/arrow/pull/35944#discussion_r1236995552


##########
python/pyarrow/tests/test_array.py:
##########
@@ -3347,6 +3347,17 @@ def test_to_pandas_timezone():
     assert s.dt.tz is not None
 
 
+@pytest.mark.pandas
+def test_to_pandas_float16_list():
+    # https://github.com/apache/arrow/issues/36168
+    arr = pa.array([[np.float16(1)], [np.float16(2)], [np.float16(3)]])
+    s = arr.to_pandas()
+    assert s is not None
+    base_refcount = sys.getrefcount(s.values.base)
+    assert base_refcount == 2

Review Comment:
   What's the reason for checking the ref count?
   
   I think you can create the expected result using numpy: `expected = np.array([1, 2, 3], dtype="float16")`, and then check that the result is the same.



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


[GitHub] [arrow] conbench-apache-arrow[bot] commented on pull request #35944: GH-36168: [C++][Python] Support halffloat for Arrow list to pandas

Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #35944:
URL: https://github.com/apache/arrow/pull/35944#issuecomment-1616619658

   Conbench analyzed the 6 benchmark runs on commit `e5de6a59`.
   
   There were 2 benchmark results indicating a performance regression:
   
   - Commit Run on `ursa-thinkcentre-m75q` at [2023-06-30 16:15:05Z](http://conbench.ursa.dev/compare/runs/e9d2e7a59dca4ddebf137775afe18269...385e9499dc52496ea4776b8ca1f73b01/)
     - [params=32768, source=cpp-micro, suite=parquet-encoding-benchmark](http://conbench.ursa.dev/compare/benchmarks/0649ed516af579208000332011fc594f...0649efff9c98745d80009a76eef555e3)
   
   - Commit Run on `ursa-i9-9960x` at [2023-07-02 09:09:08Z](http://conbench.ursa.dev/compare/runs/a3b98d82bf1e4b8191d940b6e04e58e3...0811e05c94ae4e098c2a3adc1352f8cd/)
     - [compression=uncompressed, dataset=fanniemae_2016Q4, file_type=feather, language=R, output_type=table](http://conbench.ursa.dev/compare/benchmarks/064a11e5f79275ef8000ee24875245be...064a1529a3b177a68000db20c490a3b6)
   
   The [full Conbench report](https://github.com/apache/arrow/runs/14717935992) has more details.


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