Fix warning about elementwise comparison to 'None'.

This PR "correctly" checks if an element is ``None`` and thus elementwise object comparison is avoided.