Skip to content

Add UDF type hinting #8361

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

Merged
merged 3 commits into from
Sep 27, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

# Inverse Distance Weighting algorithm (DWA)
@f.pandas_udf("YEAR integer, VALUE double", f.PandasUDFType.GROUPED_MAP)
def phx_dw_compute(year, df) -> pd.DataFrame:
def phx_dw_compute(year: tuple, df: pd.DataFrame) -> pd.DataFrame:
# This adjusts the rainfall / snowfall in Phoenix for a given year using Inverse Distance Weighting
# based on each weather station's distance to Phoenix. The closer a station is to Phoenix, the higher
# its measurement is weighed.
Expand All @@ -119,6 +119,13 @@ def phx_dw_compute(year, df) -> pd.DataFrame:
# so we negate the square and square root to combine this into:
#
# idf = 1 / ((x1-x2)^2 + (y1-y2)^2))
#
# Args:
# year: a tuple containing a single 4-digit integer value for this group's year
# df: a pandas dataframe
#
# Returns:
# A new pandas dataframe

# Latitude and longitude of Phoenix
PHX_LATITUDE = 33.4484
Expand Down