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

DecodingParameters.insert_default errors on new declaration #1158

Open
CBroz1 opened this issue Oct 8, 2024 · 0 comments
Open

DecodingParameters.insert_default errors on new declaration #1158

CBroz1 opened this issue Oct 8, 2024 · 0 comments

Comments

@CBroz1
Copy link
Member

CBroz1 commented Oct 8, 2024

From a new database, I ran

from spyglass.decoding.v1.core import DecodingParameters
DecodingParameters().insert_default()
Error Stack
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 DecodingParameters().insert_default()

File ~/wrk/spyglass/src/spyglass/decoding/v1/core.py:59, in DecodingParameters.insert_default(cls)
     56 @classmethod
     57 def insert_default(cls):
     58     """Insert default decoding parameters"""
---> 59     cls.insert(cls.contents, skip_duplicates=True)

File ~/wrk/spyglass/src/spyglass/decoding/v1/core.py:68, in DecodingParameters.insert(self, rows, *args, **kwargs)
     62 """Override insert to convert classes to dict before inserting"""
     63 for row in rows:
     64     # params = row["decoding_params"] # my edits
     65     # if hasattr(params, "__dict__"):
     66     #     params = vars(params)
     67     row["decoding_params"] = convert_classes_to_dict(
---> 68         vars(row["decoding_params"])
     69     )
     70 super().insert(rows, *args, **kwargs)

TypeError: vars() argument must have __dict__ attribute

It seems vars is being attempted on a dict.

Skipping `vars`...
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 1
----> 1 DecodingParameters().insert_default()

File ~/wrk/spyglass/src/spyglass/decoding/v1/core.py:59, in DecodingParameters.insert_default(cls)
     56 @classmethod
     57 def insert_default(cls):
     58     """Insert default decoding parameters"""
---> 59     cls.insert(cls.contents, skip_duplicates=True)

File ~/wrk/spyglass/src/spyglass/decoding/v1/core.py:67, in DecodingParameters.insert(self, rows, *args, **kwargs)
     65     if hasattr(params, "__dict__"):
     66         params = vars(params)
---> 67     row["decoding_params"] = convert_classes_to_dict(params)
     68 super().insert(rows, *args, **kwargs)

File ~/wrk/spyglass/src/spyglass/decoding/v1/dj_decoder_conversion.py:185, in convert_classes_to_dict(params)
    183 params = copy.deepcopy(params)
    184 try:
--> 185     params["environments"] = [
    186         _convert_environment_to_dict(env) for env in params["environments"]
    187     ]
    188 except TypeError:
    189     params["environments"] = [
    190         _convert_environment_to_dict(params["environments"])
    191     ]

File ~/wrk/spyglass/src/spyglass/decoding/v1/dj_decoder_conversion.py:186, in <listcomp>(.0)
    183 params = copy.deepcopy(params)
    184 try:
    185     params["environments"] = [
--> 186         _convert_environment_to_dict(env) for env in params["environments"]
    187     ]
    188 except TypeError:
    189     params["environments"] = [
    190         _convert_environment_to_dict(params["environments"])
    191     ]

File ~/wrk/spyglass/src/spyglass/decoding/v1/dj_decoder_conversion.py:158, in _convert_environment_to_dict(env)
    156 def _convert_environment_to_dict(env: Environment) -> dict:
    157     """Converts an Environment instance into a dictionary so that datajoint can store it"""
--> 158     if env.track_graph is not None:
    159         track_graph = env.track_graph
    160         env.track_graph = {
    161             "node_positions": [
    162                 v["pos"] for v in dict(track_graph.nodes).values()
    163             ],
    164             "edges": list(track_graph.edges),
    165         }

AttributeError: 'dict' object has no attribute 'track_graph'

Editing the insert to detect the utility of vars, there's still an issue with the environment-to-dict process on a contents stored as dict

Given that this tables is already a lookup, the inclusion of insert_default is just for parity with other params tables, and could be removed. Or it could super().insert

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

No branches or pull requests

1 participant