Skip to content

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

@mariosasko

Description

@mariosasko

🐛 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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions