Skip to content

Floating point errors in nb_tie() #17

@fpavogt

Description

@fpavogt

Describe the bug
The np.histogram() function inside nb_tie() is subject to floating point errors. This can cause a mismatch, at times, with the R and/or Matlab implementations of the code (e.g. see mannkendall/Matlab#3).

To Reproduce
In the case of nb_tie_test2_in.csv, the first problematic case is bin 147 with edges [0.205, 0.215).

The data contains the number 0.215, which should belong to bin 148 with edges [0.215, 0.225) (all bins are semi-open on the right in np.histogram()). But in my case, it falls into bin 147 because, when plotted fully, the edges are:
[0.20500000000000007, 0.21500000000000008). That is, floating point errors make the bin edge slightly larger than it should be.

Expected behavior
We cannot fix floating point errors ... but can we make this function more robust against them ? Maybe through the use of Decimals (https://docs.python.org/2/library/decimal.html) ?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions