This should better be:

```python
        if not hasattr(density_estimator, 'score_samples'):
            raise TypeError('Invalid density_estimator: %s. Missing required score_samples method.')
```