Skip to content

Commit

Permalink
[BEAM-13867] Drop NaNs returned by nlargest in flight_delays example …
Browse files Browse the repository at this point in the history
…pipeline (apache#16801)
  • Loading branch information
TheNeuralBit authored and Naireen Hussain committed Feb 18, 2022
1 parent 2d39f91 commit 71f6608
Showing 1 changed file with 5 additions and 3 deletions.
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

0 comments on commit 71f6608

Please sign in to comment.