Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

base_component.BaseComponent.__str__ method raising KeyError #23

Closed
aaronlelevier opened this issue Mar 28, 2019 · 2 comments · Fixed by #25
Closed

base_component.BaseComponent.__str__ method raising KeyError #23

aaronlelevier opened this issue Mar 28, 2019 · 2 comments · Fixed by #25
Assignees
Labels

Comments

@aaronlelevier
Copy link
Contributor

I got a KeyError when calling this method: base_component.BaseComponent.__str__

Here is the code to reproduce:

import os
from tfx.utils.dsl_utils import csv_input
from tfx.components.example_gen.csv_example_gen.component import CsvExampleGen

_taxi_root = os.path.join(os.environ['HOME'], 'taxi')
_data_root = os.path.join(_taxi_root, 'data/simple')
examples = csv_input(_data_root)
example_gen = CsvExampleGen(input_base=examples)
print(example_gen)

The error trace is:

/Users/alelevier/Documents/github/tfx/tfx/components/base/base_component.pyc in __str__(self)
     89         input_dict=self.input_dict,
     90         outputs=self.outputs,
---> 91         exec_properties=self.exec_properties)
     92 
     93   def __repr__(self):

KeyError: '\n  component_name'

I looked at the method, it needs use double {{ and }} so change from:

  def __str__(self):
    return """
{
  component_name: {component_name},
  unique_name: {unique_name},
  driver: {driver},
  executor: {executor},
  input_dict: {input_dict},
  outputs: {outputs},
  exec_properties: {exec_properties}
}
    """.format(  # pylint: disable=missing-format-argument-key
        component_name=self.component_name,
        unique_name=self.unique_name,
        driver=self.driver,
        executor=self.executor,
        input_dict=self.input_dict,
        outputs=self.outputs,
        exec_properties=self.exec_properties)

To:

  def __str__(self):
    return """
{{
  component_name: {component_name},
  unique_name: {unique_name},
  driver: {driver},
  executor: {executor},
  input_dict: {input_dict},
  outputs: {outputs},
  exec_properties: {exec_properties}
}}
    """.format(  # pylint: disable=missing-format-argument-key
        component_name=self.component_name,
        unique_name=self.unique_name,
        driver=self.driver,
        executor=self.executor,
        input_dict=self.input_dict,
        outputs=self.outputs,
        exec_properties=self.exec_properties)
@ruoyu90
Copy link
Contributor

ruoyu90 commented Apr 1, 2019

Thanks for the finding and the fix! I approved the PR and it will be merged soon.

@ruoyu90 ruoyu90 closed this as completed Apr 1, 2019
@ruoyu90 ruoyu90 added ready to pull Ready to pull for internal review/testing. and removed ready to pull Ready to pull for internal review/testing. labels Apr 1, 2019
@aaronlelevier
Copy link
Contributor Author

aaronlelevier commented Apr 1, 2019 via email

tfx-copybara pushed a commit that referenced this issue Apr 1, 2019
…_str__ method

Please approve this CL. It will be submitted automatically, and its GitHub pull request will be marked as merged.

Imported from GitHub PR #25

Fixes #23

I thought it'd be better to do a quick PR for this small fix.

I wanted to write a unit test, but couldn't run the tests by calling down to python file name. I opened #24 to ask how to run the tests.

Happy to write a unit test for this. I just didn't have time this morning to figure out the test suite.

Copybara import of the project:

  - 2c62b3f fix KeyError when calling 'base_component.BaseComponent._... by aaronlelevier <aaron.lelevier@gmail.com>
  - 7d80d4c Merge 2c62b3f into 76c9d... by Aaron Lelevier <aaron.lelevier@gmail.com>

PiperOrigin-RevId: 241409102
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants