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

question_options should be allowed to be a list of strings or numbers #505

Closed
rbyh opened this issue May 15, 2024 · 2 comments
Closed

question_options should be allowed to be a list of strings or numbers #505

rbyh opened this issue May 15, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@rbyh
Copy link
Contributor

rbyh commented May 15, 2024

I want to create multiple choice, checkbox, rank, etc., question types where the agent is prompted to select among answer options that are lists, but lists are not allowed.

To reproduce:

options = [[1,2,3], [4,5,6], [7,8,9]]

from edsl.questions import QuestionMultipleChoice

q_choice = QuestionMultipleChoice(
    question_name = "choice",
    question_text = "Which is the best list of numbers?",
    question_options = options
)

Error that is thrown:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[21], line 3
      1 from edsl.questions import QuestionMultipleChoice
----> 3 q_choice = QuestionMultipleChoice(
      4     question_name = "choice",
      5     question_text = "Which is the best list of numbers?",
      6     question_options = options
      7 )

File [~/edsl/edsl/questions/QuestionMultipleChoice.py:35](http://localhost:8888/lab/tree/~/edsl/edsl/questions/QuestionMultipleChoice.py#line=34), in QuestionMultipleChoice.__init__(self, question_name, question_text, question_options)
     33 self.question_name = question_name
     34 self.question_text = question_text
---> 35 self.question_options = question_options

File [~/edsl/edsl/questions/descriptors.py:57](http://localhost:8888/lab/tree/~/edsl/edsl/questions/descriptors.py#line=56), in BaseDescriptor.__set__(self, instance, value)
     55 def __set__(self, instance, value: Any) -> None:
     56     """Set the value of the attribute."""
---> 57     self.validate(value, instance)
     58     instance.__dict__[self.name] = value
     59     if self.name == "_instructions":

File [~/edsl/edsl/questions/descriptors.py:261](http://localhost:8888/lab/tree/~/edsl/edsl/questions/descriptors.py#line=260), in QuestionOptionsDescriptor.validate(self, value, instance)
    257 if len(value) < Settings.MIN_NUM_OPTIONS:
    258     raise QuestionCreationValidationError(
    259         f"Too few question options (got {value})."
    260     )
--> 261 if len(value) != len(set(value)):
    262     raise QuestionCreationValidationError(
    263         f"Question options must be unique (got {value})."
    264     )
    265 if not self.linear_scale:

TypeError: unhashable type: 'list'
@rbyh rbyh added the enhancement New feature or request label May 15, 2024
@rbyh
Copy link
Contributor Author

rbyh commented May 24, 2024

We should also allow numbers as options for QuestionMultipleChoice
It is not obvious that you need to convert to strings "1", 10", etc.

@rbyh
Copy link
Contributor Author

rbyh commented May 25, 2024

Thanks!

@rbyh rbyh closed this as completed May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants