Skip to content

Numpy array raises error when used in create_junctions function specifically in geodata attribute #694

@oakca

Description

@oakca

Describe the bug
When a numpy array of (x, y) tuples are used as geodata in create_junctions() function, an error is raised. When converted the same array to a list then it works.

here is the nodes file: https://congasnet-my.sharepoint.com/:u:/g/personal/okan_akca_congas_net/ET8b6UY-W9pIurtbPBMkT94BLqnS27GoyyHx15GbflWqsQ?e=qTBPBt

To Reproduce

import geopandas as gpd
import pandapipes as pp

n_ = gpd.read_file('nodes.geojson', driver='GeoJSON').set_index('id')

net = pp.create_empty_network(fluid='hydrogen')
nodes = pp.create_junctions(
        net,
        nr_junctions=len(n_),
        pn_bar=50,
        tfluid_k=283.15,
        height_m=n_['height'].values,
        name=n_['name'].values,
        index=n_.index,
        geodata=n_['geometry'].map(lambda p: (p.x, p.y)).values)

Error message

Traceback (most recent call last):
  File "C:\.venv\Lib\site-packages\IPython\core\interactiveshell.py", line 3577, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-18-cb2062836528>", line 3, in <module>
    nodes = pp.create_junctions(
            ^^^^^^^^^^^^^^^^^^^^
  File "C:\.venv\Lib\site-packages\pandapipes\create.py", line 1135, in create_junctions
    net.junction_geodata.loc[index, ["x", "y"]] = geodata
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "C:\.venv\Lib\site-packages\pandas\core\indexing.py", line 885, in __setitem__
    iloc._setitem_with_indexer(indexer, value, self.name)
  File "C:\.venv\Lib\site-packages\pandas\core\indexing.py", line 1893, in _setitem_with_indexer
    self._setitem_with_indexer_split_path(indexer, value, name)
  File "C:\.venv\Lib\site-packages\pandas\core\indexing.py", line 1978, in _setitem_with_indexer_split_path
    raise ValueError(
ValueError: Must have equal len keys and value when setting with an iterable

Expected behavior
it works when numpy array changed to list via n_['geometry'].map(lambda p: (p.x, p.y)).values.tolist(), it should also work with numpy array since the other attributes raise no errors.

Python environment (please complete the following information):

  • OS: Windows 11
  • pandapipes 0.11.0
  • geopandas

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions