C2W2 - 'NoneType' object has no attribute 'values'

Trying to troubleshoot this transform code, eliminated all but the first transformation:

Scale these features to the z-score.

for key in _DENSE_FLOAT_FEATURE_KEYS:
    # Scale these features to the z-score.
    outputs[_transformed_name(key)] = tft.scale_to_z_score(inputs[key])

and am receiving this error when I try to run the transform:

AttributeError: ‘NoneType’ object has no attribute ‘values’

Almost everything up to this point is given code, and seems to be working fine.
I appreciate any ideas about what might be happening here.

All of the code prior to the assignment works fine, and I’ve verified the transform file is writing and importing.

This is the code to run the transform :

Instantiate the Transform component

transform = Transform(
examples=example_gen.outputs[‘examples’],
schema=schema_gen.outputs[‘schema’],
module_file=os.path.abspath(_traffic_transform_module_file))

Run the component

context.run(transform)

I’ve verified each of the transform inputs: examples, schema, and module file

I have also tried to enable and disable cache when running the transform.

I am receiving warnings about empty tensors:

Tensor(“mean/mean_and_var/Placeholder:0”, shape=(), dtype=float32)
WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class ‘NoneType’>
WARNING:apache_beam.typehints.typehints:Ignoring return_type hint: <class ‘NoneType’>
WARNING:apache_beam.typehints.typehints:Ignoring send_type hint: <class ‘NoneType’>

The outputs is an empty dictionary.

Something does not seem right here. Everything indicates that I have done the assignment correctly.

Here is an example, the first transformation:

# Scale these features to the z-score.
for key in _DENSE_FLOAT_FEATURE_KEYS:
    # Scale these features to the z-score.
    outputs[_transformed_name(key)] = tft.scale_to_z_score(inputs[key])

If I limit the transformation code to just this example, then I get the error:
‘NoneType’ object has no attribute ‘values’

So I think it must be either

  1. the way the inputs are being passed to preprocessing_fn
  2. or the way they are being referenced in the transform file,
  3. or as suggested in another topic, some issue with the saving and referencing of components and files.

What are some good ways to verify 1, 2, and 3? Thanks!

Hi Tina! The values property can be seen in the _fill_in_missing() helper function. So there might be part of the code that is using it and passing a None object to it. But as you said, you’ve already commented out the other parts of the code so that shouldn’t be a problem. Will investigate why that is happening. I think if we solve the issue in your other post, then this will also be resolved. Will keep you posted. Thanks.

Just comment the loop about categorical features that is suggested keep them as is

This was resolved - the code was correct and the error went away by itself. I received the same warnings but the execution details returned with the output, and it passed the grader. Must have been something related to the browser or the environment, is the best guess at the moment. Thanks.