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

ValueError: mutable default <class 'numpy.ndarray'> for field offset is not allowed: use default_factory #153

Closed
CoderThomasB opened this issue Jun 12, 2023 · 6 comments

Comments

@CoderThomasB
Copy link

I'm new to this project and I have just installed it using pip, but when I try to run the map-machine command both with and without options it crashes with this python error:

Traceback (most recent call last):
  File "/home/thomas/.local/bin/map-machine", line 5, in <module>
    from map_machine.main import main
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/main.py", line 21, in <module>
    from map_machine.ui.cli import parse_arguments
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/ui/cli.py", line 5, in <module>
    from map_machine.map_configuration import BuildingMode, DrawingMode, LabelMode
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/map_configuration.py", line 9, in <module>
    from map_machine.pictogram.icon import ShapeExtractor, IconSet
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/pictogram/icon.py", line 367, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1223, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1213, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'numpy.ndarray'> for field offset is not allowed: use default_factory

The expected behaviour is of course that it doesn't crash.

I'm using python 3.11 which is much higher than 3.9 which is the suggested version but when I run it with 3.9 it says that ModuleNotFoundError: No module named 'map_machine'

I'm also using the fedora distribution of Linux.

If there is anything else that I have left out of this bug report, then I would be happy to add it in a comment.

@FabienSailliet
Copy link

I have the same issue. I would have loved to try this program that looks like exactly what I need, but this issue prevents me to do so. It looks like it has been fixed in the pending merge request, will it be released soon?

@enzet
Copy link
Owner

enzet commented Jul 6, 2023

I've merged the request by @phillies.

Please, reopen the issue if the problem still persists.

@enzet enzet closed this as completed Jul 6, 2023
@CoderThomasB
Copy link
Author

I've just pulled the latest changes from the git repo which includes the fix and the issue is persisting with what looks to be the same back trace.

Traceback (most recent call last):
  File "/home/thomas/Projects/map-machine/map_machine/__main__.py", line 2, in <module>
    from map_machine.main import main
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/main.py", line 21, in <module>
    from map_machine.ui.cli import parse_arguments
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/ui/cli.py", line 5, in <module>
    from map_machine.map_configuration import BuildingMode, DrawingMode, LabelMode
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/map_configuration.py", line 9, in <module>
    from map_machine.pictogram.icon import ShapeExtractor, IconSet
  File "/home/thomas/.local/lib/python3.11/site-packages/map_machine/pictogram/icon.py", line 367, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1223, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 1213, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 958, in _process_class
    cls_fields.append(_get_field(cls, name, type, kw_only))
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/dataclasses.py", line 815, in _get_field
    raise ValueError(f'mutable default {type(f.default)} for field '
ValueError: mutable default <class 'numpy.ndarray'> for field offset is not allowed: use default_factory

@enzet
Copy link
Owner

enzet commented Jul 7, 2023

Hi, @CoderThomasB, thank you for the quick feedback!

There may have been a problem with the update because I haven't updated the minor version. I'll fix it. If the problem persists after that, could you please specify the command you are using so that I can try to reproduce it?

@CoderThomasB
Copy link
Author

@enzet Oops, I thought I was running the new version's main.py file from the git repo, but on a closer look it's actually just importing other stuff from the old pip version.

Fetching and installing the new version, using pip install git+https://github.com/enzet/map-machine, works. So this issue is solved for me at least!

Thanks for responding to my message quickly and merging the patch. I'm having a fun time playing around with your amazing map renderer, now that it's working!

@enzet
Copy link
Owner

enzet commented Jul 9, 2023

@CoderThomasB I believe version bumping was needed for pip install --upgrade to work correctly.

Thank you, hope the project is useful for you!

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

3 participants