Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdks/python: replace applymap with map in DataFrame #33605

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/dataframe/frames_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ def test_applymap_na_action(self):
# 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import datetime
import html
import logging
import warnings
from datetime import timedelta
from typing import Optional

Expand Down Expand Up @@ -351,11 +350,7 @@ def display(self, updating_pv=None):
]
# 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
Expand Down Expand Up @@ -420,7 +415,7 @@ def _display_dataframe(self, data, update=None):
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.
Expand Down
Loading