You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by jr...@apache.org on 2025/01/15 15:09:36 UTC

(beam) branch master updated: sdks: replace `applymap` with `map` in `DataFrame` (#33605)

This is an automated email from the ASF dual-hosted git repository.

jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new e36a8311c5d sdks: replace `applymap` with `map` in `DataFrame` (#33605)
e36a8311c5d is described below

commit e36a8311c5d9b698508201c97c1012c1d2e41e9a
Author: Mohamed Awnallah <69...@users.noreply.github.com>
AuthorDate: Wed Jan 15 17:09:30 2025 +0200

    sdks: replace `applymap` with `map` in `DataFrame` (#33605)
---
 sdks/python/apache_beam/dataframe/frames_test.py                 | 2 +-
 .../runners/interactive/display/pcoll_visualization.py           | 9 ++-------
 2 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/sdks/python/apache_beam/dataframe/frames_test.py b/sdks/python/apache_beam/dataframe/frames_test.py
index f99b77e446a..bfe87dab52e 100644
--- a/sdks/python/apache_beam/dataframe/frames_test.py
+++ b/sdks/python/apache_beam/dataframe/frames_test.py
@@ -886,7 +886,7 @@ class DeferredFrameTest(_AbstractFrameTest):
     # doctest framework
     df = pd.DataFrame([[pd.NA, 2.12], [3.356, 4.567]])
     self._run_test(
-        lambda df: df.applymap(lambda x: len(str(x)), na_action='ignore'),
+        lambda df: df.map(lambda x: len(str(x)), na_action='ignore'),
         df,
         # TODO: generate proxy using naive type inference on fn
         check_proxy=False)
diff --git a/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py b/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py
index d767a15a345..0bb3d1ba187 100644
--- a/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py
+++ b/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization.py
@@ -26,7 +26,6 @@ import base64
 import datetime
 import html
 import logging
-import warnings
 from datetime import timedelta
 from typing import Optional
 
@@ -351,11 +350,7 @@ class PCollectionVisualization(object):
     ]
     # String-ify the dictionaries for display because elements of type dict
     # cannot be ordered.
-    with warnings.catch_warnings():
-      # TODO(yathu) switch to use DataFrame.map when dropped pandas<2.1 support
-      warnings.filterwarnings(
-          "ignore", message="DataFrame.applymap has been deprecated")
-      data = data.applymap(lambda x: str(x) if isinstance(x, dict) else x)
+    data = data.map(lambda x: str(x) if isinstance(x, dict) else x)
 
     if updating_pv:
       # Only updates when data is not empty. Otherwise, consider it a bad
@@ -420,7 +415,7 @@ class PCollectionVisualization(object):
     format_window_info_in_dataframe(data)
     # Convert the dataframe into rows, each row looks like
     # [column_1_val, column_2_val, ...].
-    rows = data.applymap(lambda x: str(x)).to_dict('split')['data']
+    rows = data.map(lambda x: str(x)).to_dict('split')['data']
     # Convert each row into dict where keys are column index in the datatable
     # to be rendered and values are data from the dataframe. Column index 0 is
     # left out to hold the int index (not part of the data) from dataframe.