@@ -1800,6 +1800,62 @@ def test_preprocessor_parameter_combinations(self):
18001800 ) # (batch_size, feature_dim)
18011801 # You can add more specific checks for each feature if needed
18021802
1803+ def test_preprocessor_with_passthrough_feature (self ):
1804+ """Test preprocessor with a passthrough feature."""
1805+ # Create features specs with a passthrough feature
1806+ features = {
1807+ "num1" : NumericalFeature (
1808+ name = "num1" ,
1809+ feature_type = FeatureType .FLOAT_NORMALIZED ,
1810+ ),
1811+ "raw_feature" : PassthroughFeature (
1812+ name = "raw_feature" ,
1813+ feature_type = FeatureType .PASSTHROUGH ,
1814+ dtype = tf .float32 ,
1815+ ),
1816+ }
1817+
1818+ # Generate and save fake data
1819+ df = generate_fake_data (features , num_rows = 20 )
1820+ df .to_csv (self ._path_data , index = False )
1821+
1822+ # Create preprocessor with passthrough feature
1823+ ppr = PreprocessingModel (
1824+ path_data = str (self ._path_data ),
1825+ features_specs = features ,
1826+ features_stats_path = self .features_stats_path ,
1827+ overwrite_stats = True ,
1828+ output_mode = OutputModeOptions .DICT ,
1829+ )
1830+
1831+ result = ppr .build_preprocessor ()
1832+
1833+ # Check if the model was created
1834+ self .assertIsInstance (result ["model" ], tf .keras .Model )
1835+
1836+ # Check if both features are in the inputs
1837+ input_names = [input_layer .name for input_layer in result ["model" ].inputs ]
1838+ self .assertIn ("num1" , input_names )
1839+ self .assertIn ("raw_feature" , input_names )
1840+
1841+ # Create a simple dataset for testing
1842+ test_data = {
1843+ "num1" : tf .constant ([[1.0 ], [2.0 ]]),
1844+ "raw_feature" : tf .constant ([[3.0 ], [4.0 ]]),
1845+ }
1846+
1847+ # Run prediction
1848+ outputs = result ["model" ](test_data )
1849+
1850+ # Check that the outputs include the passthrough feature
1851+ self .assertIsInstance (outputs , dict )
1852+ self .assertIn ("raw_feature" , outputs )
1853+
1854+ # Verify that the passthrough feature values are unchanged
1855+ np .testing .assert_array_almost_equal (
1856+ outputs ["raw_feature" ].numpy (), test_data ["raw_feature" ].numpy ()
1857+ )
1858+
18031859
18041860class TestPreprocessingModel_åNumericalEmbedding (unittest .TestCase ):
18051861 @classmethod
0 commit comments