astropy / astropy/halotools

Importing halotools.mock_observables changes how numpy floating point errors are handled

Open
#911 1 comment 0 reactions 1 assignee Claimed by @aphearin View on GitHub
bug mock-observables
Dominant language
Python
Stars
120
Forks
70
PR merge metrics
No merged PRs in 30d

Description

On import, there are a couple of places where halotools runs something like:

https://github.com/astropy/halotools/blob/fb15d29a2392674b0638ff0757c463d84136dbd8/halotools/mock_observables/two_point_clustering/angular_tpcf.py#L23

which will change this globally. In practice, maybe not a huge deal, but this would surprise me as a user (and might catch me out if I was expecting numpy to warn me on divide by 0) and also means there aren't these warnings in the rest of halotools (where you might want them).

```
@>>> import numpy as np
@>>> np.geterr()
{'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
@>>> import halotools.sim_manager
@>>> halotools.sim_manager.rockstar_hlist_reader.np.geterr()
{'divide': 'warn', 'over': 'warn', 'under': 'ignore', 'invalid': 'warn'}
@>>> import halotools.mock_observables
@>>> halotools.sim_manager.rockstar_hlist_reader.np.geterr()
{'divide': 'ignore', 'over': 'warn', 'under': 'ignore', 'invalid': 'ignore'}
@>>> np.geterr()
{'divide': 'ignore', 'over': 'warn', 'under': 'ignore', 'invalid': 'ignore'}
```

A fix would be to just set this at the start of each function that might need it and then unset it on the way out. I'm not sure how best to do this in python but maybe a with statement that sets it on `__enter__` and unsets on `__exit__`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.