Q:

AssertionError: negative sum of square deviations

As part of a larger project, I am writing a function that takes in a dict of dicts of ints and returns a dict with each "outer" key linked to a tuple of the mean and standard deviation of that sub dictionary (i.e.  (mean(dict[key1]), stdev(dict[key1])) ). I am operating on a large dataset (the source file is a 2.8 GB csv file) and am getting an Assertion Error while calculating the standard deviation of one of the sub dicts. 
While I will (and currently am) tracking down the sub dict that caused the error below, I'm curious about what general situation could cause it so I can try to avoid it if it happens further into my dataset.
The error message I receive is: 
AssertionError: negative sum of square deviations: -3734262324235.697754 
from the code:
import statistics as stat

try: #Check for single value error
    std = stat.stdev(val)
except stat.StatisticsError:
    std = 0

A:

The code in statiscs.py is pure Python - you seem to be a victim of a weird overflow error in the Fraction class, when processing the internal "sum of quares) statistics._ss  function. 
I think the best thing you can do now is to isntrument the_ss function in the statistics.py file itself with an "if" and a call to pdb.set_trace to find interactively which data is causing the errors (there is a comment in the code that this part is subject to rounding errors). It calculates a fraction that shuld be zero - but for rounding errors, and squares that fraction. But upon squaring, the already large denominator is squared itself - which is probably triggering a bug inside Python's Fraction, and returning an extremely large value when it should be just close to zero.
Such an "if" clause can allow you to (1) bypass the error condition and run your code to the end, forcing the value to zero when the error is found; (2) note down the values that cause the error, and report that as  a bug to the Python language itself.

