C2W2: Exercise 7 - module 'traffic_constants' has no attribute 'preprocessing_fn'

I’ve generated ‘traffic_transoform.py’ and passed the test which generated transformed_data.
However, when I execute the following code, I got an error message saying ’

AttributeError: module ‘traffic_constants’ has no attribute ‘preprocessing_fn’

Could someone point me to the right direction?

# Ignore TF warning messages
tf.get_logger().setLevel('ERROR')
# Instantiate the Transform component

transform = tfx.components.Transform(
    examples=example_gen.outputs['examples'],
    schema=schema_gen.outputs['schema'],
module_file=os.path.abspath(_traffic_constants_module_file))

# Run the component.
# The `enable_cache` flag is disabled in case you need to update your transform module file.
context.run(transform, enable_cache=False)

Please run the cell that defines def preprocessing_fn(inputs):

One way to check your implementation is to open the file traffic_transform.py and ensure that the function is present. The writefile magic writes the contents of the cell to the provided file.

Hi thank you for your reply.

I checked and traffic_transform.py has def preprocessing_fn(inputs) but the same error message shows up. Why traffic_transform matters when traffic constants is the one giving the error. traffic_constants precedes traffic_transform ?

traffic_transform.py imports traffic_constants.
For transformation, you should rely on traffic_transform.py.

Hi thank you for your continuous support.
Sorry I don’t quite understand.

The error is AttributeError: module ‘traffic_constants’ has no attribute ‘preprocessing_fn’. And def preprocessing_fn appears on “traffic_transformation

To this error, you said that it may have to do with the dependency from the traffic_constants. So I checked the cell that tests preprocessing_fn

** code from Exercise 6 **

[code removed - moderator]

And it passed the preprocessing_fn test

[code removed - moderator]

It showed the error below but I consider the test was successful.

WARNING:apache_beam.options.pipeline_options:Discarding unparseable args: ['/opt/conda/lib/python3.8/site-packages/ipykernel_launcher.py', '-f', '/home/jovyan/.local/share/jupyter/runtime/kernel-06e901d7-e022-4a80-8063-a50e5631f40d.json']
WARNING:root:Make sure that locally built Python SDK docker image has Python 3.8 interpreter.

If it passed the test, doesn’t it mean that traffic_transformation successfully called traffic_constants?

Please click my name and message your notebook as an attachment.

The traffic transform module imports traffic constants and contains the definition of preprocessing_fn. You should use this file instead of the traffic constants file when performing the transform operation. Please fix the module parameter of the Transform component and run your notebook. In case of error, message the notebook.

Thank you! By switching the path variable in exercise 7 from 'traffic_constants' to 'traffic_transform' I was able to properly refer 'traffic_transform.py' which includes preprocessing_fn module.

Now that I look at it, it looks silly but I was scratching my head for 2 whole days.
Thanks again Balaji!