mapmanager / MapManagerCore

A Python library with the core functionality of MapManager
0 stars 0 forks source link

Problems running editing code examples in the jupyter notebook #3

Closed cudmore closed 3 months ago

cudmore commented 3 months ago

I am trying to run some of the code in the example jupyter notebook to edit spine annotation but it is failing?

This is the code

id = map.addSpine(segmentId="1", x=1,y=2,z=3)
map.updateSpine(spineId=id, value={
  "x": 1,
})

And this is the error that the code to updateSpine() throws.

     75 def updateSpine(self, spineId: str, value: Union[dict, gp.GeoSeries, pd.Series], replaceLog=False, skipLog=False):
     76     """
     77     Set the spine with the given ID to the specified value.
     78 
   (...)
     81         value (Union[dict, gp.Series, pd.Series]): The value to set for the spine.
     82     """
---> 83     return self._update(AnnotationType.Point, spineId, value, replaceLog, skipLog)
...
-> 6105     raise ValueError("Can only compare identically-labeled Series objects")
   6107 lvalues = self._values
   6108 rvalues = extract_array(other, extract_numpy=True, extract_range=True)

Any thoughts?

cudmore commented 3 months ago

Here is the error from the command line. It is occurring in base_mutations diff = original.compare(updated).

Traceback (most recent call last):
  File "/Users/cudmore/Sites/MapManagerCore/sandbox/addToPoints.py", line 56, in <module>
    tryAddSpine()
  File "/Users/cudmore/Sites/MapManagerCore/sandbox/addToPoints.py", line 51, in tryAddSpine
    map.updateSpine(id, value={
  File "/Users/cudmore/Sites/MapManagerCore/mapmanagercore/annotations/base/base_mutation.py", line 83, in updateSpine
    return self._update(AnnotationType.Point, spineId, value, replaceLog, skipLog)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cudmore/Sites/MapManagerCore/mapmanagercore/annotations/base/base_mutation.py", line 116, in _update
    diff = original.compare(updated)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cudmore/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/series.py", line 3355, in compare
    return super().compare(
           ^^^^^^^^^^^^^^^^
  File "/Users/cudmore/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/generic.py", line 10118, in compare
    mask = ~((self == other) | (self.isna() & other.isna()))
              ^^^^^^^^^^^^^
  File "/Users/cudmore/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/ops/common.py", line 76, in new_method
    return method(self, other)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/cudmore/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/arraylike.py", line 40, in __eq__
    return self._cmp_method(other, operator.eq)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cudmore/opt/miniconda3/envs/mmc-env/lib/python3.11/site-packages/pandas/core/series.py", line 6105, in _cmp_method
    raise ValueError("Can only compare identically-labeled Series objects")
ValueError: Can only compare identically-labeled Series objects
cudmore commented 3 months ago

A-ha, it is because "x" is not a column in the backend dataframe, x is part of a geoPandas Point().

If I modify an actually existing column name it works fine, like

    id = "0"
    map.updateSpine(id, value={
    "xBackgroundOffset": 1,
    })
Suhayb-A commented 3 months ago

Thanks for the feedback! I refined the api and added type checks so the errors are more legible. The new API also uses typed update dictionaries so interfacing with the API should be easier.