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

[BEAM-13867] Drop NaNs returned by nlargest in flight_delays example pipeline #16801

Merged
merged 1 commit into from
Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions sdks/python/apache_beam/examples/dataframe/flight_delays.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def get_mean_delay_at_top_airports(airline_df):
'departure_airport': 'airport'
}).airport.value_counts()
total = arr + dep
# Note we keep all to include duplicates.
# This ensures the result is deterministic
top_airports = total.nlargest(10, keep='all')
# Note we keep all to include duplicates - this ensures the result is
# deterministic.
# NaNs can be included in the output in pandas 1.4.0 and above, so we
# explicitly drop them.
top_airports = total.nlargest(10, keep='all').dropna()
at_top_airports = airline_df['arrival_airport'].isin(
top_airports.index.values)
return airline_df[at_top_airports].mean()
Expand Down