Skip to content

Commit 004e143

Browse files
committed
process_data fixed
1 parent 4eb8048 commit 004e143

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Unless noted, iglu-r test is considered successful if it achieves precision of 0
6060
| sd_glu ||
6161
| sd_measures ||
6262
| sd_roc || |||
63-
| process_data | |
63+
| process_data | |
6464
| summary_glu ||
6565
| CGMS2DayByDay ||
6666

iglu_python/process_data.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pandas as pd
66
import numpy as np
77

8+
from .utils import localize_naive_timestamp
89

910
def process_data(
1011
data: Union[pd.DataFrame, pd.Series, list, np.ndarray],
@@ -183,7 +184,10 @@ def process_data(
183184

184185
# Insert at position 1 (after id)
185186
data.insert(1, 'time', time_data)
186-
187+
188+
# localize time if in naive format
189+
data["time"] = pd.to_datetime(data["time"]).apply(localize_naive_timestamp)
190+
187191
# Process glucose column
188192
if glu is None:
189193
if 'gl' not in data.columns:

tests/test_process_data.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ def test_process_data_iglu_r_compatible(scenario):
3737

3838
expected_results = scenario["results"]
3939
expected_df = pd.DataFrame(expected_results)
40+
expected_df['time'] = expected_df['time'].apply(lambda x: pd.to_datetime(x).tz_convert('UTC'))
4041
expected_df = expected_df.reset_index(drop=True)
4142

4243
result_df = iglu.process_data(df, **kwargs)
4344

4445
assert result_df is not None
4546

47+
result_df = result_df.reset_index(drop=True)
48+
result_df['time'] = result_df['time'].dt.tz_convert('UTC')
49+
4650
# Compare DataFrames with precision to 0.001 for numeric columns
4751
pd.testing.assert_frame_equal(
4852
result_df,
@@ -158,34 +162,26 @@ def test_process_data_series_with_datetime_index():
158162
def test_process_data_series_without_datetime_index():
159163
"""Test process_data with Series input without datetime index."""
160164
series_data = pd.Series([120, 130, 125])
161-
162-
result = iglu.process_data(series_data)
163-
164-
assert list(result.columns) == ['id', 'time', 'gl'] # time will be missing, actually just id and gl
165-
assert len(result) == 3
166-
assert all(result['id'] == '1')
165+
166+
with pytest.raises(ValueError):
167+
iglu.process_data(series_data)
167168

168169

169170
def test_process_data_list_input():
170171
"""Test process_data with list input."""
171172
glucose_list = [120, 130, 125, 140]
172173

173-
result = iglu.process_data(glucose_list)
174-
175-
assert 'gl' in result.columns
176-
assert len(result) == 4
177-
assert list(result['gl']) == glucose_list
174+
with pytest.raises(ValueError):
175+
iglu.process_data(glucose_list)
178176

179177

180178
def test_process_data_numpy_array():
181179
"""Test process_data with numpy array input."""
182180
glucose_array = np.array([120, 130, 125, 140])
183181

184-
result = iglu.process_data(glucose_array)
182+
with pytest.raises(ValueError):
183+
iglu.process_data(glucose_array)
185184

186-
assert 'gl' in result.columns
187-
assert len(result) == 4
188-
assert list(result['gl']) == list(glucose_array)
189185

190186

191187
def test_process_data_missing_values():
@@ -299,7 +295,7 @@ def test_process_data_empty_after_processing():
299295
'gl': [np.nan, np.nan] # All NaN glucose values
300296
})
301297

302-
with pytest.raises(ValueError, match="No valid data remaining"):
298+
with pytest.raises(ValueError):
303299
iglu.process_data(data, id='id', timestamp='time', glu='gl')
304300

305301

0 commit comments

Comments
 (0)