1515# specific language governing permissions and limitations
1616# under the License.
1717import math
18+ import warnings
1819from datetime import date , datetime , time , timezone
1920
2021import numpy as np
@@ -1086,10 +1087,10 @@ def test_hash_functions(df):
10861087
10871088def test_temporal_functions (df ):
10881089 df = df .select (
1089- f .date_part (literal ( "month" ) , column ("d" )),
1090- f .datepart (literal ( "year" ) , column ("d" )),
1091- f .date_trunc (literal ( "month" ) , column ("d" )),
1092- f .datetrunc (literal ( "day" ) , column ("d" )),
1090+ f .date_part ("month" , column ("d" )),
1091+ f .datepart ("year" , column ("d" )),
1092+ f .date_trunc ("month" , column ("d" )),
1093+ f .datetrunc ("day" , column ("d" )),
10931094 f .date_bin (
10941095 literal ("15 minutes" ).cast (pa .string ()),
10951096 column ("d" ),
@@ -1100,7 +1101,7 @@ def test_temporal_functions(df):
11001101 f .to_timestamp_seconds (literal ("2023-09-07 05:06:14.523952" )),
11011102 f .to_timestamp_millis (literal ("2023-09-07 05:06:14.523952" )),
11021103 f .to_timestamp_micros (literal ("2023-09-07 05:06:14.523952" )),
1103- f .extract (literal ( "day" ) , column ("d" )),
1104+ f .extract ("day" , column ("d" )),
11041105 f .to_timestamp (
11051106 literal ("2023-09-07 05:06:14.523952000" ), literal ("%Y-%m-%d %H:%M:%S.%f" )
11061107 ),
@@ -2160,16 +2161,51 @@ def test_date_part_native_str(self):
21602161 ctx = SessionContext ()
21612162 df = ctx .from_pydict ({"a" : ["2021-07-15T00:00:00" ]})
21622163 df = df .select (f .to_timestamp (column ("a" )).alias ("a" ))
2163- result = df .select (f .date_part ("year" , column ("a" )).alias ("y" )).collect ()
2164+ with warnings .catch_warnings ():
2165+ warnings .simplefilter ("error" , DeprecationWarning )
2166+ result = df .select (f .date_part ("year" , column ("a" )).alias ("y" )).collect ()
21642167 assert result [0 ].column (0 )[0 ].as_py () == 2021
21652168
2169+ @pytest .mark .parametrize (
2170+ ("func" , "name" ),
2171+ [
2172+ pytest .param (f .date_part , "date_part" , id = "date_part" ),
2173+ pytest .param (f .datepart , "datepart" , id = "datepart" ),
2174+ pytest .param (f .extract , "extract" , id = "extract" ),
2175+ ],
2176+ )
2177+ def test_date_part_expr_part_warns_deprecated (self , func , name ):
2178+ with pytest .warns (
2179+ DeprecationWarning ,
2180+ match = rf"Passing Expr for { name } \(\) argument 'part' is deprecated" ,
2181+ ):
2182+ expr = func (literal ("year" ), column ("a" ))
2183+ assert expr is not None
2184+
21662185 def test_date_trunc_native_str (self ):
21672186 ctx = SessionContext ()
21682187 df = ctx .from_pydict ({"a" : ["2021-07-15T12:34:56" ]})
21692188 df = df .select (f .to_timestamp (column ("a" )).alias ("a" ))
2170- result = df .select (f .date_trunc ("month" , column ("a" )).alias ("t" )).collect ()
2189+ with warnings .catch_warnings ():
2190+ warnings .simplefilter ("error" , DeprecationWarning )
2191+ result = df .select (f .date_trunc ("month" , column ("a" )).alias ("t" )).collect ()
21712192 assert str (result [0 ].column (0 )[0 ].as_py ()) == "2021-07-01 00:00:00"
21722193
2194+ @pytest .mark .parametrize (
2195+ ("func" , "name" ),
2196+ [
2197+ pytest .param (f .date_trunc , "date_trunc" , id = "date_trunc" ),
2198+ pytest .param (f .datetrunc , "datetrunc" , id = "datetrunc" ),
2199+ ],
2200+ )
2201+ def test_date_trunc_expr_part_warns_deprecated (self , func , name ):
2202+ with pytest .warns (
2203+ DeprecationWarning ,
2204+ match = rf"Passing Expr for { name } \(\) argument 'part' is deprecated" ,
2205+ ):
2206+ expr = func (literal ("month" ), column ("a" ))
2207+ assert expr is not None
2208+
21732209 def test_left_native_int (self ):
21742210 ctx = SessionContext ()
21752211 df = ctx .from_pydict ({"a" : ["the cat" ]})
0 commit comments