Skip to content

Commit d8dc848

Browse files
committed
correcting documentation mistake and making test self contained
1 parent 587d8fb commit d8dc848

File tree

2 files changed

+83
-19
lines changed

2 files changed

+83
-19
lines changed

python/hsfs/hopsworks_udf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class HopsworksUdf:
149149
dropped_feature_names : `Optional[List[str]]`. The feature name corresponding to the arguments names that are dropped
150150
feature_name_prefix: `Optional[str]`. Prefixes if any used in the feature view.
151151
output_column_names: `Optional[List[str]]`. The names of the output columns returned from the transformation function.
152-
generate_output_col_names: `Optional[bool]`. Generate default output column names for the transformation function. Default's to True.
152+
generate_output_col_names: `bool`. Generate default output column names for the transformation function. Default's to True.
153153
"""
154154

155155
# Mapping for converting python types to spark types - required for creating pandas UDF's.

python/tests/test_transformation_function.py

+82-18
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def test2(col1):
246246

247247
assert tf.hopsworks_udf.to_dict() == udf_json
248248

249-
def test_generate_output_column_names_one_argument_one_output_type(self):
249+
def test_generate_output_column_names_one_argument_one_output_type_mdt(self):
250250
@udf(int)
251251
def test_func(col1):
252252
return col1 + 1
@@ -258,14 +258,19 @@ def test_func(col1):
258258
)
259259
assert mdt._get_output_column_names() == ["test_func_col1_"]
260260

261+
def test_generate_output_column_names_one_argument_one_output_type_odt(self):
262+
@udf(int)
263+
def test_func(col1):
264+
return col1 + 1
265+
261266
odt = TransformationFunction(
262267
featurestore_id=10,
263268
hopsworks_udf=test_func,
264269
transformation_type=TransformationType.ON_DEMAND,
265270
)
266271
assert odt._get_output_column_names() == ["test_func"]
267272

268-
def test_generate_output_column_names_one_argument_one_output_type_prefix(self):
273+
def test_generate_output_column_names_one_argument_one_output_type_prefix_mdt(self):
269274
@udf(int)
270275
def test_func(col1):
271276
return col1 + 1
@@ -278,7 +283,13 @@ def test_func(col1):
278283
transformation_type=TransformationType.MODEL_DEPENDENT,
279284
)
280285
assert mdt._get_output_column_names() == ["test_func_prefix_col1_"]
281-
assert mdt.output_column_names == ["prefix_test_func_prefix_col1_"]
286+
287+
def test_generate_output_column_names_one_argument_one_output_type_prefix_odt(self):
288+
@udf(int)
289+
def test_func(col1):
290+
return col1 + 1
291+
292+
test_func._feature_name_prefix = "prefix_"
282293

283294
odt = TransformationFunction(
284295
featurestore_id=10,
@@ -288,7 +299,7 @@ def test_func(col1):
288299
assert odt._get_output_column_names() == ["test_func"]
289300
assert odt.output_column_names == ["prefix_test_func"]
290301

291-
def test_generate_output_column_names_multiple_argument_one_output_type(self):
302+
def test_generate_output_column_names_multiple_argument_one_output_type_mdt(self):
292303
@udf(int)
293304
def test_func(col1, col2, col3):
294305
return col1 + 1
@@ -299,14 +310,20 @@ def test_func(col1, col2, col3):
299310
transformation_type=TransformationType.MODEL_DEPENDENT,
300311
)
301312
assert mdt._get_output_column_names() == ["test_func_col1_col2_col3_"]
313+
314+
def test_generate_output_column_names_multiple_argument_one_output_type_odt(self):
315+
@udf(int)
316+
def test_func(col1, col2, col3):
317+
return col1 + 1
318+
302319
odt = TransformationFunction(
303320
featurestore_id=10,
304321
hopsworks_udf=test_func,
305322
transformation_type=TransformationType.ON_DEMAND,
306323
)
307324
assert odt._get_output_column_names() == ["test_func"]
308325

309-
def test_generate_output_column_names_multiple_argument_one_output_type_prefix(
326+
def test_generate_output_column_names_multiple_argument_one_output_type_prefix_mdt(
310327
self,
311328
):
312329
@udf(int)
@@ -326,6 +343,16 @@ def test_func(col1, col2, col3):
326343
assert mdt.output_column_names == [
327344
"prefix_test_func_prefix_col1_prefix_col2_prefix_col3_"
328345
]
346+
347+
def test_generate_output_column_names_multiple_argument_one_output_type_prefix_odt(
348+
self,
349+
):
350+
@udf(int)
351+
def test_func(col1, col2, col3):
352+
return col1 + 1
353+
354+
test_func._feature_name_prefix = "prefix_"
355+
329356
odt = TransformationFunction(
330357
featurestore_id=10,
331358
hopsworks_udf=test_func,
@@ -334,7 +361,9 @@ def test_func(col1, col2, col3):
334361
assert odt._get_output_column_names() == ["test_func"]
335362
assert odt.output_column_names == ["prefix_test_func"]
336363

337-
def test_generate_output_column_names_single_argument_multiple_output_type(self):
364+
def test_generate_output_column_names_single_argument_multiple_output_type_mdt(
365+
self,
366+
):
338367
@udf([int, float, int])
339368
def test_func(col1):
340369
return pd.DataFrame(
@@ -352,7 +381,7 @@ def test_func(col1):
352381
"test_func_col1_2",
353382
]
354383

355-
def test_generate_output_column_names_single_argument_multiple_output_type_prefix(
384+
def test_generate_output_column_names_single_argument_multiple_output_type_prefix_mdt(
356385
self,
357386
):
358387
@udf([int, float, int])
@@ -379,7 +408,9 @@ def test_func(col1):
379408
"prefix_test_func_prefix_col1_2",
380409
]
381410

382-
def test_generate_output_column_names_multiple_argument_multiple_output_type(self):
411+
def test_generate_output_column_names_multiple_argument_multiple_output_type_mdt(
412+
self,
413+
):
383414
@udf([int, float, int])
384415
def test_func(col1, col2, col3):
385416
return pd.DataFrame(
@@ -397,7 +428,7 @@ def test_func(col1, col2, col3):
397428
"test_func_col1_col2_col3_2",
398429
]
399430

400-
def test_generate_output_column_names_multiple_argument_multiple_output_type_prefix(
431+
def test_generate_output_column_names_multiple_argument_multiple_output_type_prefix_mdt(
401432
self,
402433
):
403434
@udf([int, float, int])
@@ -462,7 +493,7 @@ def test_func(col1, statistics=stats):
462493
== "On-Demand Transformation functions cannot use statistics, please remove statistics parameters from the functions"
463494
)
464495

465-
def test_alias_one_output(self):
496+
def test_alias_one_output_mdt(self):
466497
@udf(int)
467498
def add_one(feature):
468499
return feature + 1
@@ -477,6 +508,11 @@ def add_one(feature):
477508

478509
assert mdt.output_column_names == ["feature_plus_one_mdt"]
479510

511+
def test_alias_one_output_odt(self):
512+
@udf(int)
513+
def add_one(feature):
514+
return feature + 1
515+
480516
odt = TransformationFunction(
481517
featurestore_id=10,
482518
hopsworks_udf=add_one,
@@ -487,7 +523,7 @@ def add_one(feature):
487523

488524
assert odt.output_column_names == ["feature_plus_one_odt"]
489525

490-
def test_alias_one_output_list(self):
526+
def test_alias_one_output_list_mdt(self):
491527
@udf(int)
492528
def add_one(feature):
493529
return feature + 1
@@ -502,6 +538,11 @@ def add_one(feature):
502538

503539
assert mdt.output_column_names == ["feature_plus_one_mdt"]
504540

541+
def test_alias_one_output_list_odt(self):
542+
@udf(int)
543+
def add_one(feature):
544+
return feature + 1
545+
505546
odt = TransformationFunction(
506547
featurestore_id=10,
507548
hopsworks_udf=add_one,
@@ -512,7 +553,7 @@ def add_one(feature):
512553

513554
assert odt.output_column_names == ["feature_plus_one_odt"]
514555

515-
def test_alias_multiple_output(self):
556+
def test_alias_multiple_output_mdt(self):
516557
@udf([int, int])
517558
def add_and_sub(feature):
518559
return feature + 1, feature - 1
@@ -530,7 +571,7 @@ def add_and_sub(feature):
530571
"feature_minus_one_mdt",
531572
]
532573

533-
def test_alias_multiple_output_list(self):
574+
def test_alias_multiple_output_list_mdt(self):
534575
@udf([int, int])
535576
def add_and_sub(feature):
536577
return feature + 1, feature - 1
@@ -548,7 +589,7 @@ def add_and_sub(feature):
548589
"feature_minus_one_mdt",
549590
]
550591

551-
def test_alias_invalid_number_column_names(self):
592+
def test_alias_invalid_number_column_names_mdt(self):
552593
@udf([int, int])
553594
def add_and_sub(feature):
554595
return feature + 1, feature - 1
@@ -567,6 +608,7 @@ def add_and_sub(feature):
567608
== "The number of output feature names provided does not match the number of features returned by the transformation function 'add_and_sub(feature)'. Pease provide exactly 2 feature name(s) to match the output."
568609
)
569610

611+
def test_alias_invalid_number_column_names_odt(self):
570612
@udf(int)
571613
def add_one(feature):
572614
return feature + 1
@@ -585,7 +627,7 @@ def add_one(feature):
585627
== "The number of output feature names provided does not match the number of features returned by the transformation function 'add_one(feature)'. Pease provide exactly 1 feature name(s) to match the output."
586628
)
587629

588-
def test_alias_invalid_type(self):
630+
def test_alias_invalid_type_mdt(self):
589631
@udf([int])
590632
def add_one(feature):
591633
return feature + 1
@@ -604,6 +646,11 @@ def add_one(feature):
604646
== "Invalid output feature names provided for the transformation function 'add_one(feature)'. Please ensure all arguments are strings."
605647
)
606648

649+
def test_alias_invalid_type_odt(self):
650+
@udf([int])
651+
def add_one(feature):
652+
return feature + 1
653+
607654
odt = TransformationFunction(
608655
featurestore_id=10,
609656
hopsworks_udf=add_one,
@@ -618,7 +665,7 @@ def add_one(feature):
618665
== "Invalid output feature names provided for the transformation function 'add_one(feature)'. Please ensure all arguments are strings."
619666
)
620667

621-
def test_alias_duplicates(self):
668+
def test_alias_duplicates_mdt(self):
622669
@udf([int, int])
623670
def add_and_sub(feature):
624671
return feature + 1, feature - 1
@@ -637,7 +684,7 @@ def add_and_sub(feature):
637684
== "Duplicate output feature names provided for the transformation function 'add_and_sub(feature)'. Please ensure all arguments names are unique."
638685
)
639686

640-
def test_call_and_alias(self):
687+
def test_call_and_alias_mdt(self):
641688
@udf(int)
642689
def add_one(feature):
643690
return feature + 1
@@ -653,6 +700,11 @@ def add_one(feature):
653700
assert mdt.output_column_names == ["feature_plus_one_mdt"]
654701
assert mdt.hopsworks_udf.transformation_features == ["feature2_mdt"]
655702

703+
def test_call_and_alias_odt(self):
704+
@udf(int)
705+
def add_one(feature):
706+
return feature + 1
707+
656708
odt = TransformationFunction(
657709
featurestore_id=10,
658710
hopsworks_udf=add_one,
@@ -664,7 +716,7 @@ def add_one(feature):
664716
assert odt.output_column_names == ["feature_plus_one_odt"]
665717
assert odt.hopsworks_udf.transformation_features == ["feature2_odt"]
666718

667-
def test_alias_invalid_length(self):
719+
def test_alias_invalid_length_mdt(self):
668720
@udf(int)
669721
def add_one(feature):
670722
return feature + 1
@@ -683,6 +735,11 @@ def add_one(feature):
683735
== "Invalid output feature names specified for the transformation function 'add_one(feature)'. Please provide names shorter than 63 characters."
684736
)
685737

738+
def test_alias_invalid_length_odt(self):
739+
@udf(int)
740+
def add_one(feature):
741+
return feature + 1
742+
686743
odt = TransformationFunction(
687744
featurestore_id=10,
688745
hopsworks_udf=add_one,
@@ -786,6 +843,13 @@ def really_long_function_name_that_exceed_63_characters_causing_invalid_name_for
786843
"really_long_function_name_that_exceed_63_characters_causing_inv"
787844
]
788845

846+
def test_generate_output_col_name_invalid_mdt(self, caplog):
847+
@udf(int)
848+
def really_long_function_name_that_exceed_63_characters_causing_invalid_name_for_on_demand_features(
849+
features,
850+
):
851+
return features
852+
789853
mdt = TransformationFunction(
790854
featurestore_id=10,
791855
hopsworks_udf=really_long_function_name_that_exceed_63_characters_causing_invalid_name_for_on_demand_features,

0 commit comments

Comments
 (0)