dimwit 0.2.4__tar.gz → 0.2.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dimwit
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: A package containing various functions and classes for fetching, transforming, and visualising data for personal metrics.
5
5
  Home-page: https://github.com/danielsoutar/dimwit
6
6
  Author: Daniel Soutar
@@ -274,25 +274,27 @@ def compute_rounded_matrix(ts, events, rounding_unit, rounding_size):
274
274
  return df.fillna(0)
275
275
 
276
276
 
277
- def pad_out_table(df, pad_t, unit):
277
+ def zero_padded_df(num_rows, num_cols, index):
278
+ return pd.DataFrame([[0] * num_cols] * num_rows, index=index)
279
+
280
+
281
+ def pad_out_table(df, pad_t, unit, pad_before=True, pad_after=True):
278
282
  # Pad out df with entries before and after boundary rows, to ensure correct
279
- # copy-on padding.
283
+ # same- (or zero-) padding.
280
284
  pad_t_days = pd.Timedelta(pad_t, unit=unit)
281
285
  pad_before_start = df.index[0] - pad_t_days
282
286
  pad_after_start = df.index[-1] + pd.Timedelta(1, unit=unit)
283
287
 
284
288
  # The index in df cannot yet be assumed to be dense - so use a date range
285
289
  # with the earliest and latest entries as reference points.
286
- pad_before = pd.date_range(pad_before_start, periods=pad_t, freq=unit)
287
- pad_after = pd.date_range(pad_after_start, periods=pad_t, freq=unit)
288
-
289
- df = pd.concat(
290
- [
291
- pd.DataFrame([df.iloc[0]] * pad_t, index=pad_before),
292
- df,
293
- pd.DataFrame([df.iloc[-1]] * pad_t, index=pad_after),
294
- ]
295
- )
290
+ index_before = pd.date_range(pad_before_start, periods=pad_t, freq=unit)
291
+ index_after = pd.date_range(pad_after_start, periods=pad_t, freq=unit)
292
+
293
+ num_rows, num_cols = pad_t, len(df.columns)
294
+ if pad_before:
295
+ df = pd.concat([zero_padded_df(num_rows, num_cols, index_before), df])
296
+ if pad_after:
297
+ df = pd.concat([zero_padded_df(num_rows, num_cols, index_after), df])
296
298
 
297
299
  return df
298
300
 
@@ -306,8 +308,6 @@ def compute_moving_average_matrix(
306
308
  df = compute_rounded_matrix(ts, events, rounding_unit, rounding_size)
307
309
  categories = df.columns
308
310
 
309
- # Pad out df with entries before and after boundary rows, to ensure correct
310
- # copy-on padding.
311
311
  df_needs_padding = window_size > 1
312
312
  if df_needs_padding:
313
313
  pad_t = (window_size - 1) // 2
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dimwit"
3
- version = "0.2.4"
3
+ version = "0.2.6"
4
4
  description = "A package containing various functions and classes for fetching, transforming, and visualising data for personal metrics."
5
5
  authors = ["Daniel Soutar <danielsoutar144@gmail.com>"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes