@@ -63,6 +63,9 @@ def check_data_columns(data: pd.DataFrame, tz="") -> pd.DataFrame:
6363 if missing_cols :
6464 raise ValueError (f"Missing required columns: { missing_cols } " )
6565
66+ # Create a copy to avoid dtype warning
67+ data = data .copy ()
68+
6669 # Check data types
6770 if not pd .api .types .is_numeric_dtype (data ["gl" ]):
6871 try :
@@ -91,9 +94,6 @@ def check_data_columns(data: pd.DataFrame, tz="") -> pd.DataFrame:
9194 if data ["gl" ].isna ().any ():
9295 warnings .warn ("Data contains missing glucose values" )
9396
94- # # convert time to datetime
95- # data.loc[:, "time"] = pd.to_datetime(data["time"])
96-
9797 # convert time to specified timezone
9898 # TODO: check if this is correct (R-implementation compatibility)
9999 # if tz and tz != "":
@@ -103,9 +103,11 @@ def check_data_columns(data: pd.DataFrame, tz="") -> pd.DataFrame:
103103 # this is implementation compatible with R implementation
104104 # but seems incorrect, as it convert time to TZ instead of localizing it to TZ
105105 if tz != "" :
106- data ["time" ] = data ["time" ].apply (localize_naive_timestamp ).dt .tz_convert (tz )
106+ # Create a copy to avoid dtype warning and properly handle timezone conversion
107+ data ["time" ] = pd .to_datetime (data ["time" ]).apply (localize_naive_timestamp ).dt .tz_convert (tz )
107108 else :
108- data ["time" ] = data ["time" ].apply (localize_naive_timestamp )
109+ # Create a copy to avoid dtype warning
110+ data ["time" ] = pd .to_datetime (data ["time" ]).apply (localize_naive_timestamp )
109111
110112 return data
111113
0 commit comments