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

Schema fails when unhashable values within lists #217

Closed
tcmoore3 opened this issue Aug 9, 2019 · 2 comments
Closed

Schema fails when unhashable values within lists #217

tcmoore3 opened this issue Aug 9, 2019 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@tcmoore3
Copy link
Member

tcmoore3 commented Aug 9, 2019

Description

When statepoints contain values that are lists containing dicts, a TypeError is raised when detect_schema() is called on the project.

To reproduce

import signac


pr = signac.init_project('gonna_fail')
j = pr.open_job({'oh': [{'hi': 'mark'}]}).init()
pr.detect_schema()

Error output

Traceback (most recent call last):
  File "reproduce-error.py", line 6, in <module>
    pr.detect_schema()
  File "/Users/tcmoore3/programs/signac/signac/contrib/project.py", line 507, in detect_schema
    return ProjectSchema.detect(statepoint_index)
  File "/Users/tcmoore3/programs/signac/signac/contrib/schema.py", line 63, in detect
    return cls({k: _collect_by_type(v) for k, v in statepoint_index})
  File "/Users/tcmoore3/programs/signac/signac/contrib/schema.py", line 63, in <dictcomp>
    return cls({k: _collect_by_type(v) for k, v in statepoint_index})
  File "/Users/tcmoore3/programs/signac/signac/contrib/project.py", line 481, in build_job_statepoint_index
    for x in _build_job_statepoint_index(jobs=self, exclude_const=exclude_const, index=index):
  File "/Users/tcmoore3/programs/signac/signac/contrib/schema.py", line 38, in _build_job_statepoint_index
    collection.index(key, build=True)
  File "/Users/tcmoore3/programs/signac/signac/contrib/collection.py", line 458, in index
    self._build_index(key)
  File "/Users/tcmoore3/programs/signac/signac/contrib/collection.py", line 415, in _build_index
    self._indexes[key] = _build_index(self._docs.values(), key, self._primary_key)
  File "/Users/tcmoore3/programs/signac/signac/contrib/collection.py", line 193, in _build_index
    index[_to_tuples(v)].add(doc[primary_key])
  File "/Users/tcmoore3/programs/signac/signac/contrib/collection.py", line 155, in __getitem__
    _float(key) if type(key) is float else key)
TypeError: unhashable type: 'dict'

System configuration

Please complete the following information:

  • Operating System: macOS 10.13.6
  • Version of Python: 3.5.5
  • Version of signac: 1.2.0
@tcmoore3
Copy link
Member Author

tcmoore3 commented Aug 9, 2019

A TypeError is also raised if a value contains a set within a list, but not if the value contains a list within a list.

import signac


pr = signac.init_project('gonna_fail')
j = pr.open_job({'oh': [{0, 0, 1, 2, 3, 3, 3}]}).init()
pr.detect_schema()
Traceback (most recent call last):
  File "reproduce-error.py", line 5, in <module>
    j = pr.open_job({'oh': [{0, 0, 1, 2, 3, 3, 3}]}).init()
  File "/Users/tcmoore3/programs/signac/signac/contrib/project.py", line 368, in open_job
    job = self.Job(project=self, statepoint=statepoint)
  File "/Users/tcmoore3/programs/signac/signac/contrib/job.py", line 61, in __init__
    self._id = calc_id(self._statepoint()) if _id is None else _id
  File "/Users/tcmoore3/programs/signac/signac/contrib/hashing.py", line 12, in calc_id
    blob = json.dumps(spec, sort_keys=True)
  File "/Users/tcmoore3/anaconda/lib/python3.5/json/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/Users/tcmoore3/anaconda/lib/python3.5/json/encoder.py", line 198, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Users/tcmoore3/anaconda/lib/python3.5/json/encoder.py", line 256, in iterencode
    return _iterencode(o, 0)
  File "/Users/tcmoore3/anaconda/lib/python3.5/json/encoder.py", line 179, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: {0, 1, 2, 3} is not JSON serializable

@vyasr
Copy link
Contributor

vyasr commented Aug 9, 2019

@tcmoore3 you're tearing me apart

@csadorf csadorf added the bug Something isn't working label Aug 9, 2019
@csadorf csadorf self-assigned this Aug 9, 2019
@csadorf csadorf added this to the v1.2.1 milestone Aug 9, 2019
csadorf added a commit that referenced this issue Aug 9, 2019
csadorf added a commit that referenced this issue Aug 9, 2019
@csadorf csadorf closed this as completed Aug 9, 2019
@bdice bdice modified the milestones: v1.2.1, v1.3.0 Dec 4, 2019
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

4 participants