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

ExampleFactory(fields).from_list does not work if the fields are in the dict format #290

Open
mariosasko opened this issue Feb 6, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@mariosasko
Copy link
Collaborator

mariosasko commented Feb 6, 2021

🐛 Bug

This is a serious bug. If ExampleFactory is instantiated with fields in the dict format, calling from_list will throw an error.
This line in ExampleFactory.from_list is the problem (self.fields is a dict so the loop is iterating over the field names):

for value, field in filter(lambda el: el[1] is not None, zip(data, self.fields)):

And this is my workaround (not tested!!!):

fields = self.fields.values() if isinstance(self.fields, dict) else self.fields
for value, field in filter(lambda el: el[1] is not None, zip(data, fields)):

The ExampleFactory tests don't cover this case.

EDIT:
The same thing happens if the fields are passed as a list and ExampleFactory.from_dict is called.

Steps to Reproduce

Example source:

>>> from podium import Field
>>> from podium.datasets import ExampleFactory
>>>
>>> fields = {'f': Field('f')}
>>> ExampleFactory(fields).from_list(['some data'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\users\mario\desktop\takelab\podium\podium\datasets\example_factory.py", line 146, in from_list
    set_example_attributes(example, field, value)
  File "c:\users\mario\desktop\takelab\podium\podium\datasets\example_factory.py", line 357, in set_example_attributes
    set_example_attributes_for_single_field(example, field, val)
  File "c:\users\mario\desktop\takelab\podium\podium\datasets\example_factory.py", line 349, in set_example_attributes_for_single_field
    for name, data in field.preprocess(val):
AttributeError: 'str' object has no attribute 'preprocess'

@mariosasko mariosasko added the bug Something isn't working label Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant