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

fix: access column values instead of DataFrame method #544

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

danielolsen
Copy link
Contributor

Pull Request doc

Purpose

Correct a bug introduced in #507.

What the code is doing

We had meant to access the "diff" column of a DataFrame, but we're instead accessing the .diff() method. This fixes that.

Testing

Tested manually. Before:

>>> from powersimdata import Scenario
>>> from powersimdata.design.investment.investment_costs import (
...     calculate_ac_inv_costs,
...     calculate_gen_inv_costs,
... )
>>> scenario = Scenario(1705)
>>> calculate_ac_inv_costs(scenario)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\DanielOlsen\repos\bes\PowerSimData\powersimdata\design\investment\investment_costs.py", line 76, in calculate_ac_inv_costs
    grid_differences.branch = grid_differences.branch.assign(
  File "C:\Python39\lib\site-packages\pandas\core\frame.py", line 3699, in assign
    data[k] = com.apply_if_callable(v, data)
  File "C:\Python39\lib\site-packages\pandas\core\common.py", line 341, in apply_if_callable
    return maybe_callable(obj, **kwargs)
  File "C:\Python39\lib\site-packages\pandas\core\frame.py", line 7260, in diff
    new_data = self._mgr.diff(n=periods, axis=bm_axis)
  File "C:\Python39\lib\site-packages\pandas\core\internals\managers.py", line 567, in diff
    return self.apply("diff", n=n, axis=axis)
  File "C:\Python39\lib\site-packages\pandas\core\internals\managers.py", line 409, in apply
    applied = getattr(b, f)(**kwargs)
  File "C:\Python39\lib\site-packages\pandas\core\internals\blocks.py", line 1272, in diff
    new_values = algos.diff(self.values, n, axis=axis, stacklevel=7)
  File "C:\Python39\lib\site-packages\pandas\core\algorithms.py", line 1918, in diff
    n = int(n)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'DataFrame'
>>> calculate_gen_inv_costs(scenario, 2025, "Moderate")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\DanielOlsen\repos\bes\PowerSimData\powersimdata\design\investment\investment_costs.py", line 393, in calculate_gen_inv_costs
    grid_differences.plant = grid_differences.plant.assign(
  File "C:\Python39\lib\site-packages\pandas\core\frame.py", line 3699, in assign
    data[k] = com.apply_if_callable(v, data)
  File "C:\Python39\lib\site-packages\pandas\core\common.py", line 341, in apply_if_callable
    return maybe_callable(obj, **kwargs)
  File "C:\Python39\lib\site-packages\pandas\core\frame.py", line 7260, in diff
    new_data = self._mgr.diff(n=periods, axis=bm_axis)
  File "C:\Python39\lib\site-packages\pandas\core\internals\managers.py", line 567, in diff
    return self.apply("diff", n=n, axis=axis)
  File "C:\Python39\lib\site-packages\pandas\core\internals\managers.py", line 409, in apply
    applied = getattr(b, f)(**kwargs)
  File "C:\Python39\lib\site-packages\pandas\core\internals\blocks.py", line 1272, in diff
    new_values = algos.diff(self.values, n, axis=axis, stacklevel=7)
  File "C:\Python39\lib\site-packages\pandas\core\algorithms.py", line 1918, in diff
    n = int(n)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'DataFrame'

After:

>>> from powersimdata import Scenario
>>> from powersimdata.design.investment.investment_costs import (
...     calculate_ac_inv_costs,
...     calculate_gen_inv_costs,
... )
>>> scenario = Scenario(1705)
>>> calculate_ac_inv_costs(scenario)
{'line_cost': 292542221726.4701, 'transformer_cost': 7594541147.697944}
>>> calculate_gen_inv_costs(scenario, 2025, "Moderate")
Technology
coal          2.750677e+10
geothermal    7.362562e+08
hydro         1.492064e+10
ng            5.826340e+10
nuclear       1.592516e+10
solar         5.741915e+11
wind          7.455055e+11
Name: cost, dtype: float64

Time estimate

2 minutes.

@danielolsen danielolsen added the bug Something isn't working label Sep 14, 2021
@danielolsen danielolsen self-assigned this Sep 14, 2021
Copy link
Collaborator

@rouille rouille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always do df["A"] to access column instead of df.A for the reason you just brought

@danielolsen danielolsen merged commit 56d3490 into develop Sep 14, 2021
@danielolsen danielolsen deleted the daniel/investment_fix branch September 14, 2021 18:43
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

Successfully merging this pull request may close these issues.

2 participants