Skip to content

Commit 3a50b39

Browse files
committed
fix: drop first/last days instead of setting to na; rename to drop_ and flag_ for clarity
1 parent d42ab31 commit 3a50b39

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/stepcount/stepcount.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ def main():
9292

9393
# Exclusion: first/last days
9494
if args.exclude_first_last is not None:
95-
data = utils.exclude_first_last_days(data, args.exclude_first_last)
95+
data = utils.drop_first_last_days(data, args.exclude_first_last)
9696

9797
# Exclusion: days with wear time below threshold
9898
if args.exclude_wear_below is not None:
99-
data = utils.exclude_wear_below_days(data, args.exclude_wear_below)
99+
data = utils.flag_wear_below_days(data, args.exclude_wear_below)
100100

101101
# Update wear time stats after exclusions
102102
info.update(utils.calculate_wear_stats(data))

src/stepcount/utils.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def calculate_wear_stats(data: pd.DataFrame):
178178
}
179179

180180

181-
def exclude_wear_below_days(
181+
def flag_wear_below_days(
182182
x: Union[pd.Series, pd.DataFrame],
183183
min_wear: str = '12H'
184184
):
@@ -217,34 +217,34 @@ def exclude_wear_below_days(
217217
return x
218218

219219

220-
def exclude_first_last_days(
220+
def drop_first_last_days(
221221
x: Union[pd.Series, pd.DataFrame],
222222
first_or_last='both'
223223
):
224224
"""
225-
Set the values of the first day, last day, or both to NaN in a time series.
225+
Drop the first day, last day, or both from a time series.
226226
227227
Parameters:
228228
- x (pd.Series or pd.DataFrame): A pandas Series or DataFrame with a DatetimeIndex representing time series data.
229-
- first_or_last (str, optional): A string indicating which days to exclude. Options are 'first', 'last', or 'both'. Default is 'both'.
229+
- first_or_last (str, optional): A string indicating which days to drop. Options are 'first', 'last', or 'both'. Default is 'both'.
230230
231231
Returns:
232-
- pd.Series or pd.DataFrame: A pandas Series or DataFrame with the values of the specified days set to NaN.
232+
- pd.Series or pd.DataFrame: A pandas Series or DataFrame with the values of the specified days dropped.
233233
234234
Example:
235-
# Exclude the first day from the series
236-
series = exclude_first_last_days(series, first_or_last='first')
235+
# Drop the first day from the series
236+
series = drop_first_last_days(series, first_or_last='first')
237237
"""
238238
if len(x) == 0:
239-
print("No data to exclude")
239+
print("No data to drop")
240240
return x
241241

242242
if first_or_last == 'first':
243-
x[x.index.date == x.index.date[0]] = np.nan
243+
x = x[x.index.date != x.index.date[0]]
244244
elif first_or_last == 'last':
245-
x[x.index.date == x.index.date[-1]] = np.nan
245+
x = x[x.index.date != x.index.date[-1]]
246246
elif first_or_last == 'both':
247-
x[(x.index.date == x.index.date[0]) | (x.index.date == x.index.date[-1])] = np.nan
247+
x = x[(x.index.date != x.index.date[0]) & (x.index.date != x.index.date[-1])]
248248
return x
249249

250250

0 commit comments

Comments
 (0)