Skip to content

Commit

Permalink
Merge pull request #59 from loosolab/55-tfcomb-changes-numpy-error-ha…
Browse files Browse the repository at this point in the history
…ndling

Fixes #55 floating-point error handling
  • Loading branch information
msbentsen authored Mar 1, 2023
2 parents 2ef8d82 + d3def4c commit 2a5c93a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.0.4 (in progress)
-------------------
- Fix for floating-point error handling (#55)

1.0.3 (23-01-2023)
------------------
- Added pyproject.toml to fix error introduced in 1.0.2 when installing with pip
Expand Down
2 changes: 1 addition & 1 deletion tfcomb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from importlib import import_module

__version__ = "1.0.3"
__version__ = "1.0.4-b"

#Set classes to be available directly from upper tfcomb, i.e. "from tfcomb import CombObj"
global_classes = ["tfcomb.objects.CombObj",
Expand Down
4 changes: 3 additions & 1 deletion tfcomb/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def _establish_node_attributes(table, node):

for attribute in columns_to_assign:
try:
p = scipy.stats.chisquare(factorized[node], f_exp=factorized[attribute])[1]
# temporary change numpy floating-point error handling
with np.errstate(all="raise"):
p = scipy.stats.chisquare(factorized[node], f_exp=factorized[attribute])[1]
except ValueError: #observed frequencies != expected frequencies
p = 0.0 #not correlated
except FloatingPointError: #sum of factorized is 0 -> all nan
Expand Down
1 change: 0 additions & 1 deletion tfcomb/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
from tfcomb.utils import *


np.seterr(all='raise') # raise errors for runtimewarnings
#pd.options.mode.chained_assignment = 'raise' # for debugging
pd.options.mode.chained_assignment = None

Expand Down
4 changes: 3 additions & 1 deletion tfcomb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,9 @@ def get_threshold(data, which="upper", percent=0.05, _n_max=10000, verbosity=0,

#Catch any exceptions from fitting
try:
params = distribution.fit(data_finite)
# temporary change numpy floating-point error handling
with np.errstate(all="raise"):
params = distribution.fit(data_finite)
except Exception as e:
logger.error("Exception ({0}) occurred while fitting data to '{1}' distribution; skipping this distribution. Error message was: {2} ".format(e.__class__.__name__, distribution.name, e))
continue
Expand Down

0 comments on commit 2a5c93a

Please sign in to comment.