{"record":{"id":"93379004303b7685","repo":"donnemartin/interactive-coding-challenges","slug":"val-cannot-be-none","errorCode":null,"errorMessage":"val cannot be None","messagePattern":"val cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"math_probability/math_ops/math_ops_solution.ipynb","lineNumber":118,"sourceCode":"    \"\\n\",\n    \"\\n\",\n    \"class Solution(object):\\n\",\n    \"\\n\",\n    \"    def __init__(self, upper_limit=100):\\n\",\n    \"        self.max = None\\n\",\n    \"        self.min = None\\n\",\n    \"        # Mean\\n\",\n    \"        self.num_items = 0\\n\",\n    \"        self.running_sum = 0\\n\",\n    \"        self.mean = None\\n\",\n    \"        # Mode\\n\",\n    \"        self.array = [0] * (upper_limit + 1)\\n\",\n    \"        self.mode_occurrences = 0\\n\",\n    \"        self.mode = None\\n\",\n    \"\\n\",\n    \"    def insert(self, val):\\n\",\n    \"        if val is None:\\n\",\n    \"            raise TypeError('val cannot be None')\\n\",\n    \"        if self.max is None or val > self.max:\\n\",\n    \"            self.max = val\\n\",\n    \"        if self.min is None or val < self.min:\\n\",\n    \"            self.min = val\\n\",\n    \"        # Calculate the mean\\n\",\n    \"        self.num_items += 1\\n\",\n    \"        self.running_sum += val\\n\",\n    \"        self.mean = self.running_sum / self.num_items\\n\",\n    \"        # Calculate the mode\\n\",\n    \"        self.array[val] += 1\\n\",\n    \"        if self.array[val] > self.mode_occurrences:\\n\",\n    \"            self.mode_occurrences = self.array[val]\\n\",\n    \"            self.mode = val\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/math_probability/math_ops/math_ops_solution.ipynb#L100-L136","documentation":"Raised by MathOps.insert (running mean/min/max/mode tracker in math_probability/math_ops) when val is None. Every statistic is updated incrementally on insert, so a None value would corrupt the accumulators; the method rejects it up front.","triggerScenarios":"Calling math_ops.insert(None), e.g. inserting a value pulled from a sparse dataset, a CSV empty cell parsed as None, or an optional function parameter forwarded unchanged.","commonSituations":"Data-ingestion loops over files/APIs with missing values; batch loaders not filtering None rows.","solutions":["Filter None values before inserting: for v in values: if v is not None: ops.insert(v)","Fix parsing to skip blank/missing entries (csv empty string, JSON null)","If None is meaningful in your domain, substitute a sentinel (e.g. 0) explicitly"],"exampleFix":"# before\nfor val in raw_values:\n    ops.insert(val)  # raw_values contains None for missing cells\n\n# after\nfor val in raw_values:\n    if val is None:\n        continue\n    ops.insert(val)","handlingStrategy":"validation","validationCode":"for v in values:\n    if v is None: continue\n    ops.insert(v)","typeGuard":"def is_number(v): return isinstance(v, (int, float))","tryCatchPattern":"try:\n    ops.insert(v)\nexcept TypeError as e:\n    logger.warning('skipping invalid value: %s', e)","preventionTips":["Filter nulls during data ingestion","Treat blank CSV/JSON cells explicitly at parse time"],"tags":["python","input-validation","none-check","statistics"],"backgroundTag":"none-argument-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}