Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Copy is not deep for weakrefs in subnetworks

クローズ 初心者向け
#1,930 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@FabianHofmann がすでに取り組んでいます。

2026年10月1日 から。

  • #1968 @FabianHofmann による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python

調査の方向性

test_network.py にある既存のテストから始め、提供されている ac_dc_network fixture を使って問題を再現します。Network.copy() が Subnetwork オブジェクトとその親参照をどのように扱うかを追跡します。テストがパスすれば完了です。コピーされた subnetworks は別個のオブジェクトで、その n 参照はコピーされたネットワークを指し、元のオブジェクトは引き続き元のネットワークを参照します。

索引モデルが issue の本文から書いたものです。

説明

Version Checks (indicate both or one)
  • I have confirmed this bug exists on the lastest release of PyPSA.

  • I have confirmed this bug exists on the current master branch of PyPSA.

Issue Description

Following #1889, copying a pypsa network first removes the weakref and then re-binds the reference to the parent network inside a Subnetwork. This re-binding uses the original network object, so the copy contains a reference to the original. This behavior results in all sorts of subtle errors when working with the copy.

Reproducible Example
"""Based on the test in test_network.py"""

def test_copy_relinks_sub_networks(ac_dc_network):
    """Copying relinks SubNetwork parent references to the copied network."""
    n = ac_dc_network
    n.determine_network_topology()
    n_copy = n.copy()
    for name in n.c.sub_networks.static.index:
        sub = n.c.sub_networks.static.obj.loc[name]
        sub_copy = n_copy.c.sub_networks.static.obj.loc[name]
        assert sub is not sub_copy
        assert sub.n is n
        assert sub_copy.n is n_copy
Expected Behavior

The test above should succeed.

Installed Versions
channels: - conda-forge dependencies: - bzip2=1.0.8=h0ad9c76_10 - ca-certificates=2026.7.22=h4c7d964_0 - colorama=0.4.6=pyhd8ed1ab_1 - exceptiongroup=1.3.1=pyhd8ed1ab_0 - icu=78.3=h5112557_2 - iniconfig=2.3.0=pyhd8ed1ab_0 - libblas=3.11.0=11_h8455456_mkl - libcblas=3.11.0=11_h2a3cdd5_mkl - libexpat=2.8.1=hac47afa_1 - libffi=3.7.0=h3d046cb_1 - libhwloc=2.13.0=default_h049141e_1000 - libiconv=1.18=hc1393d2_3 - liblapack=3.11.0=11_hf9ab0e9_mkl - liblzma=5.8.3=hfd05255_1 - libmpdec=4.0.0=hfd05255_2 - libpython=3.14.7=h4f90d01_106_cp314 - libsqlite=3.53.4=hf5d6505_1 - libwinpthread=12.0.0.r4.gg4f2fc60ca=h57928b3_10 - libxml2=2.15.4=he095d88_0 - libxml2-16=2.15.4=h3cfd58e_0 - libzlib=1.3.2=hfd05255_3 - llvm-openmp=23.1.1=h49e36cd_0 - mkl=2026.1.0=hac47afa_235 - numpy=2.5.3=py314h02f10f6_0 - openssl=3.6.4=hf411b9b_0 - packaging=26.3=pyhc364b38_0 - pandas-stubs=3.0.5.260914=pyhd8ed1ab_1 - pip=26.2.1=pyh145f28c_0 - pluggy=1.6.0=pyhf9edf01_1 - pygments=2.21.0=pyhcf101f3_0 - pytest=9.1.1=pyhc364b38_2 - python=3.14.7=h53f6dd8_106_cp314 - python_abi=3.14=9_cp314 - tbb=2023.1.0=hdcfe883_0 - tk=8.6.13=h967ab96_4 - tomli=2.4.1=pyhcf101f3_0 - types-pytz=2026.3.1.20260727=pyhcf101f3_0 - typing_extensions=4.16.0=pyhcf101f3_0 - ucrt=10.0.26100.0=h57928b3_0 - vc=14.5=ha367084_41 - vc14_runtime=14.51.36247=habf1de7_41 - vcomp14=14.51.36247=habf1de7_41 - zstd=1.5.7=h534d264_7 - pip: - annotated-types==0.8.0 - bottleneck==1.6.0 - branca==0.8.2 - cachebox==5.2.3 - certifi==2026.7.22 - cftime==1.6.5 - charset-normalizer==3.5.1 - click==8.5.0 - cloudpickle==3.1.2 - contourpy==1.4.0 - cycler==0.12.1 - dask==2026.8.0 - deepdiff==9.1.0 - deprecation==2.1.0 - folium==0.20.0 - fonttools==4.65.0 - fsspec==2026.7.0 - geoalchemy2==0.20.0 - geojson==3.3.0 - geopandas==1.1.4 - greenlet==3.5.6 - highspy==1.15.1 - idna==3.19 - indigo-base==0.12.0 - indigo-sql-app==0.4.0.dev5+g545271b31 - jinja2==3.1.6 - joblib==1.6.0 - kiwisolver==1.5.1 - linopy==0.9.1 - locket==1.0.0 - lxml==6.1.3 - markupsafe==3.0.3 - matplotlib==3.11.2 - narwhals==2.26.0 - netcdf4==1.7.4 - networkx==3.6.1 - numexpr==2.14.2 - orderly-set==5.5.0 - pandapower==3.1.2 - pandas==3.0.5 - partd==1.4.2 - pillow==12.3.0 - platformdirs==4.11.9 - plotly==7.1.0 - polars==1.44.2 - polars-runtime-32==1.44.2 - psycopg2-binary==2.9.13 - pyarrow==25.0.1 - pydantic==2.13.5 - pydantic-core==2.46.5 - pydeck==0.9.3 - pyogrio==0.13.0 - pyparsing==3.3.2 - pyproj==3.8.0 - pypsa==1.3.0 - pypsa-plus==0.1.0 - python-dateutil==2.9.0.post0 - pytz==2026.3.post1 - pyyaml==6.0.3 - rapidfuzz==3.14.6 - requests==2.34.2 - scikit-learn==1.9.1 - scipy==1.18.1 - seaborn==0.13.2 - shapely==2.1.2 - six==1.17.0 - sqlalchemy==2.0.54 - threadpoolctl==3.7.0 - toolz==1.1.0 - tqdm==4.70.1 - typing-inspection==0.4.4 - tzdata==2026.4 - urllib3==2.8.0 - validators==0.35.0 - xarray==2026.7.0 - xyzservices==2026.9.1
主要言語
Python
スター
2.2k
フォーク
712
平均マージ
1日 9時間
マージ済み PR(30日)
38

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PyPSA/PyPSA のほかの issue

PyPSA/PyPSA の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。