Skip to content

Commit be18b7c

Browse files
committed
[MINOR][PYTHON][DOCS] Fix the type hint for extract, date_part and datepart
### What changes were proposed in this pull request? Fix the type hint for `extract`, `date_part` and `datepart` ### Why are the changes needed? argument `field` never supports column name: ```python In [6]: df = spark.createDataFrame([(datetime.datetime(2015, 4, 8, 13, 8, 15), "YEAR",)], ['ts', 'field']) In [7]: df.select(sf.extract("field", "ts")) ... AnalysisException: [NON_FOLDABLE_ARGUMENT] The function `extract` requires the parameter `field` to be a foldable expression of the type "STRING", but the actual argument is a non-foldable. SQLSTATE: 42K08 ``` ### Does this PR introduce _any_ user-facing change? yes, doc only change ### How was this patch tested? ci ### Was this patch authored or co-authored using generative AI tooling? no Closes #48613 from zhengruifeng/fix_extract_hint. Authored-by: Ruifeng Zheng <[email protected]> Signed-off-by: Ruifeng Zheng <[email protected]>
1 parent 35d2ef9 commit be18b7c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

python/pyspark/sql/connect/functions/builtin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,21 +3190,21 @@ def dayname(col: "ColumnOrName") -> Column:
31903190
dayname.__doc__ = pysparkfuncs.dayname.__doc__
31913191

31923192

3193-
def extract(field: "ColumnOrName", source: "ColumnOrName") -> Column:
3193+
def extract(field: Column, source: "ColumnOrName") -> Column:
31943194
return _invoke_function_over_columns("extract", field, source)
31953195

31963196

31973197
extract.__doc__ = pysparkfuncs.extract.__doc__
31983198

31993199

3200-
def date_part(field: "ColumnOrName", source: "ColumnOrName") -> Column:
3200+
def date_part(field: Column, source: "ColumnOrName") -> Column:
32013201
return _invoke_function_over_columns("date_part", field, source)
32023202

32033203

32043204
extract.__doc__ = pysparkfuncs.extract.__doc__
32053205

32063206

3207-
def datepart(field: "ColumnOrName", source: "ColumnOrName") -> Column:
3207+
def datepart(field: Column, source: "ColumnOrName") -> Column:
32083208
return _invoke_function_over_columns("datepart", field, source)
32093209

32103210

python/pyspark/sql/functions/builtin.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8564,15 +8564,15 @@ def dayname(col: "ColumnOrName") -> Column:
85648564

85658565

85668566
@_try_remote_functions
8567-
def extract(field: "ColumnOrName", source: "ColumnOrName") -> Column:
8567+
def extract(field: Column, source: "ColumnOrName") -> Column:
85688568
"""
85698569
Extracts a part of the date/timestamp or interval source.
85708570

85718571
.. versionadded:: 3.5.0
85728572

85738573
Parameters
85748574
----------
8575-
field : :class:`~pyspark.sql.Column` or str
8575+
field : :class:`~pyspark.sql.Column`
85768576
selects which part of the source should be extracted.
85778577
source : :class:`~pyspark.sql.Column` or str
85788578
a date/timestamp or interval column from where `field` should be extracted.
@@ -8600,15 +8600,15 @@ def extract(field: "ColumnOrName", source: "ColumnOrName") -> Column:
86008600

86018601

86028602
@_try_remote_functions
8603-
def date_part(field: "ColumnOrName", source: "ColumnOrName") -> Column:
8603+
def date_part(field: Column, source: "ColumnOrName") -> Column:
86048604
"""
86058605
Extracts a part of the date/timestamp or interval source.
86068606

86078607
.. versionadded:: 3.5.0
86088608

86098609
Parameters
86108610
----------
8611-
field : :class:`~pyspark.sql.Column` or str
8611+
field : :class:`~pyspark.sql.Column`
86128612
selects which part of the source should be extracted, and supported string values
86138613
are as same as the fields of the equivalent function `extract`.
86148614
source : :class:`~pyspark.sql.Column` or str
@@ -8637,15 +8637,15 @@ def date_part(field: "ColumnOrName", source: "ColumnOrName") -> Column:
86378637

86388638

86398639
@_try_remote_functions
8640-
def datepart(field: "ColumnOrName", source: "ColumnOrName") -> Column:
8640+
def datepart(field: Column, source: "ColumnOrName") -> Column:
86418641
"""
86428642
Extracts a part of the date/timestamp or interval source.
86438643

86448644
.. versionadded:: 3.5.0
86458645

86468646
Parameters
86478647
----------
8648-
field : :class:`~pyspark.sql.Column` or str
8648+
field : :class:`~pyspark.sql.Column`
86498649
selects which part of the source should be extracted, and supported string values
86508650
are as same as the fields of the equivalent function `extract`.
86518651
source : :class:`~pyspark.sql.Column` or str

0 commit comments

Comments
 (0)