For numeric data you should be doing a numeric comparison, not a string comparison.  This should simply be ``self.density != -1.0``  String comparison of numeric data is error prone (often yielding false negatives) and inefficient.  This code will be pumped through a C++ compiler, which is a champ at doing numerical comparisons like this one.