@@ -275,16 +275,17 @@ def transform_me(input1, input2, out):
275275
276276
277277def test_transform_polars_transform_two_inputs (spark_df_return_data_one , spark_df_return_data_two , transforms_context ):
278- from transforms .api import Input , Output , transform_polars
278+ from transforms .api import Input , Output , TransformContext , transform_polars
279279
280280 @transform_polars (
281281 Output ("/output/to/dataset" ),
282282 input1 = Input ("/input1" ),
283283 input2 = Input ("/input2" ),
284284 )
285- def transform_me (input1 , input2 ) -> DataFrame :
285+ def transform_me (ctx , input1 , input2 ) -> DataFrame :
286286 assert_frame_equal (input1 .to_pandas (), spark_df_return_data_one .toPandas ())
287287 assert_frame_equal (input2 .to_pandas (), spark_df_return_data_two .toPandas ())
288+ assert isinstance (ctx , TransformContext ) # ctx is our TransformContext
288289 return input1 .extend (input2 )
289290
290291 df = transform_me .compute (transforms_context )
@@ -358,20 +359,34 @@ def transform_me(input1: pd.DataFrame) -> pd.DataFrame:
358359
359360
360361def test_transform_pandas_one_input_with_ctx (spark_df_return_data_one , transforms_context ):
361- from transforms .api import Input , Output , TransformContext , transform_pandas
362+ from transforms .api import Input , Output , TransformContext , lightweight , transform_pandas
363+
364+ expected_df = spark_df_return_data_one .toPandas ()
362365
363366 @transform_pandas (Output ("/output/to/dataset" ), input1 = Input ("/input1" ))
364367 def transform_me (ctx , input1 : pd .DataFrame ) -> pd .DataFrame :
365368 assert isinstance (input1 , pd .DataFrame )
366369 assert isinstance (ctx , TransformContext ) # ctx is our TransformContext
367370 assert isinstance (ctx .spark_session , SparkSession ) # ctx.spark_session is a SparkSession
368- assert_frame_equal (input1 , spark_df_return_data_one . toPandas () )
371+ assert_frame_equal (input1 , expected_df )
369372 return input1
370373
371374 df = transform_me .compute (transforms_context )
372375 assert isinstance (df , pd .DataFrame )
373376 assert_frame_equal (df , spark_df_return_data_one .toPandas ())
374377
378+ @lightweight
379+ @transform_pandas (Output ("/output/to/dataset" ), input1 = Input ("/input1" ))
380+ def transform_me (ctx , input1 : pd .DataFrame ) -> pd .DataFrame :
381+ assert isinstance (input1 , pd .DataFrame )
382+ assert isinstance (ctx , TransformContext ) # ctx is our TransformContext
383+ assert_frame_equal (input1 , expected_df )
384+ return input1
385+
386+ df = transform_me .compute (transforms_context )
387+ assert isinstance (df , pd .DataFrame )
388+ assert_frame_equal (df , expected_df )
389+
375390
376391def test_transform_pandas_two_inputs (spark_df_return_data_one , spark_df_return_data_two , transforms_context ):
377392 from transforms .api import Input , Output , TransformContext , transform_pandas
@@ -502,6 +517,20 @@ def transform_me(output1, input1):
502517 assert "will have no effect" in record_message
503518
504519
520+ def test_lightweight_transforms_with_context (transforms_context ):
521+ from transforms .api import Input , Output , TransformContext , lightweight , transform
522+
523+ @lightweight ()
524+ @transform (
525+ output1 = Output ("/output/to/dataset" ),
526+ input1 = Input ("/input1" ),
527+ )
528+ def transform_me (ctx , output1 , input1 ):
529+ assert isinstance (ctx , TransformContext ) # ctx is our TransformContext
530+
531+ transform_me .compute (transforms_context )
532+
533+
505534def test_transforms_with_incremental ():
506535 from transforms .api import Input , Output , incremental , transform
507536
@@ -587,3 +616,17 @@ def transform_me(input1):
587616 return input1
588617
589618 transform_me .compute (transforms_context )
619+
620+
621+ def test_transform_context_auth_header (transforms_context ):
622+ from transforms .api import Input , Output , transform_df
623+
624+ @transform_df (
625+ Output ("output1" ),
626+ input1 = Input ("/input1" ),
627+ )
628+ def transform_me (ctx , input1 ):
629+ assert ctx .auth_header == "Bearer test_transform_context_auth_header_token"
630+ return input1
631+
632+ transform_me .compute (transforms_context )
0 commit comments