Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions data_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def normalize(values):
mn = min(values)
mx = max(values)
return [(v - mn) / (mx - mn) for v in values]
Comment on lines +1 to +4

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage: normalize() has two unguarded crash paths that no test currently exercises:

  • Empty listmin([]) raises ValueError. There is no guard before calling min/max.
  • All-identical values — when every element is the same, mx - mn == 0, causing ZeroDivisionError on the return line.

Both will blow up in production on valid-looking inputs. The uniform-values case is especially sneaky because a caller has no obvious reason to expect a crash.

A minimal fix for the zero-division case:

Suggested change
def normalize(values):
mn = min(values)
mx = max(values)
return [(v - mn) / (mx - mn) for v in values]
def normalize(values):
mn = min(values)
mx = max(values)
if mx == mn:
return [0.0] * len(values)
return [(v - mn) / (mx - mn) for v in values]
  • Mark as noise



def flatten(nested):
result = []
for item in nested:
if isinstance(item, list):
result.extend(flatten(item))
else:
result.append(item)
return result


def chunk(lst, size):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage: chunk(lst, 0) raises ValueError: range() arg 3 must not be zero with no helpful message. Since size comes from the caller, a zero or negative value is a plausible mistake. Add a guard and a clear error:

if size <= 0:
    raise ValueError(f"size must be a positive integer, got {size}")
  • Mark as noise

return [lst[i:i + size] for i in range(0, len(lst), size)]


def merge_dicts(a, b):
out = dict(a)
for k, v in b.items():
if k in out and isinstance(out[k], dict) and isinstance(v, dict):
out[k] = merge_dicts(out[k], v)
else:
out[k] = v
return out
Loading