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

Grid dataframe values are shared via the MemoryCache #443

Closed
danielolsen opened this issue Apr 6, 2021 · 3 comments
Closed

Grid dataframe values are shared via the MemoryCache #443

danielolsen opened this issue Apr 6, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@danielolsen
Copy link
Contributor

danielolsen commented Apr 6, 2021

If we modify the values for a dataframe for a Grid object that's been loaded into the Memory cache, they seem to be modified in new instantiated grids of the same interconnect.

>>> from powersimdata import Grid
>>> grid1 = Grid("Texas")
Reading bus.csv
Reading plant.csv
Reading gencost.csv
Reading branch.csv
Reading dcline.csv
Reading sub.csv
Reading bus2sub.csv
Reading zone.csv
>>> grid1.plant.groupby("type").sum().Pmax
type
coal       14501.59
hydro        555.10
ng         68642.42
nuclear     5138.60
solar       2460.20
wind       19062.63
Name: Pmax, dtype: float64
>>> grid1.plant.Pmax = 0
>>> grid1.plant.groupby("type").sum().Pmax
type
coal       0
hydro      0
ng         0
nuclear    0
solar      0
wind       0
Name: Pmax, dtype: int64
>>> grid2 = Grid("Texas")
>>> grid2.plant.groupby("type").sum().Pmax
type
coal       0
hydro      0
ng         0
nuclear    0
solar      0
wind       0
Name: Pmax, dtype: int64
>>> grid1 is grid2
False
>>> grid1.plant is grid2.plant
False
@danielolsen danielolsen added the bug Something isn't working label Apr 6, 2021
@danielolsen
Copy link
Contributor Author

The following test reproduces it in a minimum working example:

def test_mem_cache_put_version_never_changes():
    cache = MemoryCache()
    key = cache_key("foo", 4)
    obj = {"key1": 42}
    cache.put(key, obj)
    obj["key2"] = 8675309
    assert "key2" not in cache.get(key)

@BainanXia
Copy link
Collaborator

BainanXia commented Apr 6, 2021

Another test:

>>> from powersimdata import Grid
>>> g1 = Grid("Texas")
Reading bus.csv
Reading plant.csv
Reading gencost.csv
Reading branch.csv
Reading dcline.csv
Reading sub.csv
Reading bus2sub.csv
Reading zone.csv
>>> g2 = Grid("Texas")
>>> g1.plant.Pmax = 0
>>> g2.plant.Pmax.sum()
110360.54000000001
>>> g3 = Grid("Texas")
>>> g3.plant.Pmax.sum()
110360.54000000001

@danielolsen
Copy link
Contributor Author

Closed via #444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants