From aa26b595bdbf16f34ca6309466c518b95b37c1c4 Mon Sep 17 00:00:00 2001 From: Paul-B98 <115164840+Paul-B98@users.noreply.github.com> Date: Mon, 27 Jan 2025 19:56:37 +0100 Subject: [PATCH] fix warnings --- pyaki/preprocessors.py | 6 +++--- pyaki/probes.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pyaki/preprocessors.py b/pyaki/preprocessors.py index 6a909c4..ef9ea52 100644 --- a/pyaki/preprocessors.py +++ b/pyaki/preprocessors.py @@ -134,7 +134,7 @@ def process(self, df: pd.DataFrame) -> pd.DataFrame: The processed urine output dataset as a pandas DataFrame. """ - df = df.groupby(self._stay_identifier).resample("1H").sum() # type: ignore + df = df.groupby(self._stay_identifier).resample("1h").sum() # type: ignore df[df["urineoutput"] == 0] = None if not self._interpolate: @@ -195,7 +195,7 @@ def process(self, df: pd.DataFrame) -> pd.DataFrame: pd.DataFrame The processed creatinine dataset as a pandas DataFrame. """ - df = df.groupby(self._stay_identifier).resample("1H").mean() # type: ignore + df = df.groupby(self._stay_identifier).resample("1h").mean() # type: ignore if not self._ffill: return df @@ -244,5 +244,5 @@ def process(self, df: pd.DataFrame) -> pd.DataFrame: pd.DataFrame The processed RRT dataset as a pandas DataFrame. """ - df = df.groupby(self._stay_identifier).resample("1H").last() # type: ignore + df = df.groupby(self._stay_identifier).resample("1h").last() # type: ignore return df.ffill() diff --git a/pyaki/probes.py b/pyaki/probes.py index acef4f2..6662a4f 100644 --- a/pyaki/probes.py +++ b/pyaki/probes.py @@ -9,6 +9,7 @@ import numpy as np import pandas as pd +from pandas import PeriodIndex from pyaki.utils import Dataset, DatasetType, approx_gte, dataset_as_df, df_to_dataset @@ -164,6 +165,8 @@ def probe( if self._patient_weight_column not in patient: raise ValueError("Missing weight for stay") + df = df.copy() + weight: pd.Series = patient[self._patient_weight_column] # fmt: off df.loc[:, self.RESNAME] = np.nan # set all urineoutput_stage values to NaN @@ -316,6 +319,9 @@ def creatinine_baseline(self, df: pd.DataFrame, patient: pd.DataFrame) -> pd.Ser pd.Series The calculated creatinine baseline values. """ + if isinstance(df.index, PeriodIndex): + df.index = df.index.to_timestamp() + if self._method == CreatinineBaselineMethod.ROLLING_FIRST: return ( df[df[self._column] > 0] @@ -547,6 +553,8 @@ def probe( pd.DataFrame The modified DataFrame with the absolute creatinine stage column added. """ + df = df.copy() + baseline_values: pd.Series = self.creatinine_baseline(df, patient) df.loc[:, self.RESNAME] = 0 @@ -623,6 +631,8 @@ def probe(self, df: pd.DataFrame, patient: pd.DataFrame, **kwargs: Any) -> pd.Da pd.DataFrame The modified DataFrame with the relative creatinine stage column added. """ + df = df.copy() + baseline_values: pd.Series = self.creatinine_baseline(df, patient) df.loc[:, self.RESNAME] = 0 @@ -676,6 +686,8 @@ def probe(self, df: pd.DataFrame) -> pd.DataFrame: pd.DataFrame The modified DataFrame with the RRT stage column added. """ + df = df.copy() + df.loc[:, self.RESNAME] = 0 df.loc[df[self._column] == 1, self.RESNAME] = 3