Skip to content

Commit

Permalink
Adopt code to pandas 1.x (#31)
Browse files Browse the repository at this point in the history
With the newest change in pandas, the frequency
of a DateTimeIndex is not automatically inferred
as expected by the previous code.
This PR makes the inferrence of the DateTimeIndex
frequency explicit.

Furthermore, it moves one function to read in files
to tests/utils.py where together with a similar
function.
  • Loading branch information
aauss authored Sep 11, 2020
1 parent 55f2171 commit d031511
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ venv.bak/
.spyderproject
.spyproject

# Visual Studio Code project settings
.vscode

# Rope project settings
.ropeproject

Expand Down
4 changes: 3 additions & 1 deletion epysurv/models/timeseries/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ def predict(self, data_generator) -> pd.DataFrame:
[time] = prediction.index
alarms.append(alarm)
times.append(time)
return pd.DataFrame({"alarm": alarms}, index=pd.DatetimeIndex(times))
return pd.DataFrame(
{"alarm": alarms}, index=pd.DatetimeIndex(times, freq="infer")
)
7 changes: 1 addition & 6 deletions tests/test_simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
SeasonalNoisePoisson,
)


def load_simulations(filepath):
simulations = pd.read_csv(
filepath, index_col=0, parse_dates=True, infer_datetime_format=True
)
return simulations
from .utils import load_simulations


@pytest.mark.parametrize(
Expand Down
10 changes: 9 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ def load_predictions(filepath):
predictions = pd.read_csv(
filepath, index_col=0, parse_dates=True, infer_datetime_format=True
).assign(alarm=lambda df: df["alarm"].astype(bool))
freq = pd.infer_freq(predictions.index)
return predictions.asfreq(freq)

return predictions

def load_simulations(filepath):
simulations = pd.read_csv(
filepath, index_col=0, parse_dates=True, infer_datetime_format=True
)
freq = pd.infer_freq(simulations.index)
return simulations.asfreq(freq)

0 comments on commit d031511

Please sign in to comment.