Skip to content

Commit

Permalink
Update dependencies (#98)
Browse files Browse the repository at this point in the history
* Refactoring `dssdata.reductions.get_taps_changes` to avoid Pandas Warnings.

The usage of `dssdata.reductions.get_taps_changes` was displaying Warning.
Thus, this commit refactor this functions to be more conscise and avoid
unecessary allocations in the memory.

Also, this commit provides a better documentation for this function.

* Fixing code highlight in docs

* Updating dependencies and bump version

* Removing poetry.lock from the repository
  • Loading branch information
felipemarkson authored Mar 22, 2023
1 parent 86c4b91 commit 14992d7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2,009 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@ dmypy.json
Sistema*/
.vscode
Meuteste*.py
.venv/
.venv/
poetry.lock
54 changes: 26 additions & 28 deletions dssdata/reductions/regs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,40 @@
import pandas
from typing import List
from operator import add


def get_taps_changes(tapDataFrame: pandas.DataFrame) -> pandas.DataFrame:
"""
Count the taps changes. That function is a reduction function.
E.g.:
If a trafo starts in tap number 4 and goes to tap number -3.
The result is 7.
`(4 -> 3 -> 2 -> 1 -> 0 -> -1 -> -2 -> -3)`
Args:
tapDataFrame: The return of [get_all_taps_number][dssdata.tools.regs.get_all_taps_number] or [get_tap_number][dssdata.tools.regs.get_tap_number].
Returns:
The number of taps changes after time series power flow.
""" # noqa

def calc_one_step_chgs(first: list, second: list):
return map(lambda data1, data2: abs(data1 - data2), first, second)

def sum_changes_taps(list_df: List[list]):
first = list_df[0]
second = list_df[1]
if len(list_df) == 2:
return calc_one_step_chgs(first, second)
else:
return map(
add,
calc_one_step_chgs(first, second),
sum_changes_taps(list_df[1:]),
)

iter_by_step = tapDataFrame.groupby(["step"])

list_df = tuple(map(lambda data: data[1]["tap"].to_list(), iter_by_step))
reg_names = tuple(
map(lambda data: data[1]["reg_name"].to_list(), iter_by_step)
)[0]

return pandas.DataFrame(
data=tuple(zip(reg_names, sum_changes_taps(list_df))),
columns=["reg_name", "number_changes_tap"],
)
mapper = {"tap": "number_changes_tap"}

def prepair_df(df, step):
return df.loc[step].reset_index(drop=True).rename(columns=mapper)

df = tapDataFrame.set_index(["step"])
steps = df.index.unique()

df_new = prepair_df(df, steps[0])
df_new["number_changes_tap"] = 0

df_prev = prepair_df(df, steps[0])

for step in steps:
df_step = prepair_df(df, step)
diff = abs(df_prev["number_changes_tap"] - df_step["number_changes_tap"])
df_new["number_changes_tap"] += diff
df_prev = df_step

return df_new
5 changes: 4 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ theme:
- navigation.instant

markdown_extensions:
- codehilite
- pymdownx.highlight:
use_pygments: true
- pymdownx.superfences


plugins:
- search
Expand Down
Loading

0 comments on commit 14992d7

Please sign in to comment.