Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DiscreteVariable: Raise an exception if values are not unique #6878

Merged
merged 4 commits into from
Nov 8, 2024

Conversation

janezd
Copy link
Contributor

@janezd janezd commented Aug 21, 2024

Issue

Closes #6877.

Description of changes

Check that all values are unique; raise an exception if not.

This does not solve any bugs, but reports them earlier.

Includes
  • Code changes
  • Tests

@markotoplak
Copy link
Member

This bug catcher is so good that it successfully reported 2 bugs on the first attempt.

@janezd janezd force-pushed the unique-discrete-values branch 2 times, most recently from 548af76 to 12367d4 Compare October 10, 2024 16:04
Copy link

codecov bot commented Oct 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.38%. Comparing base (c6a79f6) to head (a410361).
Report is 32 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6878      +/-   ##
==========================================
- Coverage   88.40%   88.38%   -0.02%     
==========================================
  Files         326      329       +3     
  Lines       71946    72468     +522     
==========================================
+ Hits        63605    64053     +448     
- Misses       8341     8415      +74     

@janezd
Copy link
Contributor Author

janezd commented Oct 10, 2024

I'm so proud of my dilligent work. :)

However, as I unintentionally wrote "This does not solve any bugs, but reports them earlier.". :)

  • Now I reimplemented the code that creates labels for discretized variables so that it increases the number of digits when necessary. When the number of digits is given as an argument (as opposed to using ContinuousVariable.str_val), it also rounds the interval threshold so that they match the printed labels.
  • The other bug was due to an invalid test.

@markotoplak markotoplak added this to the 3.38.0 milestone Oct 21, 2024
int(-np.log10(mindiff)))
maxdigits = np.finfo(npoints.dtype).precision + 2
for digits in range(mindigits, maxdigits + 1):
npoints = np.round(points, digits)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that np.round and floating point formatter do the same thing. They probably do, but why did you not rather make strings directly and count these?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, see https://numpy.org/doc/2.0/reference/generated/numpy.round.html, they are not the same. :)

@markotoplak
Copy link
Member

Ok, I found some nitpicky issues. I can fix it myself if you agree with my suggestions.

@markotoplak
Copy link
Member

I replaced np.round with round. The results are a bit different, but no implementation was wrong (see tests).

I could not make a test case up where the old implementation would have actual problems, for example, points that would not correspond exactly to limits, but I can not guarantee one does not exist either. So, this seems safer, but I can not really say that the previous implementation was wrong.

@markotoplak
Copy link
Member

The difference between Python's and numpy's rounding.

n = 2.3455; npn = np.float_(n)
round(n, 3)
Out[17]: 2.345
round(npn, 3)  # this one is fun
Out[18]: 2.346
print("%0.3f" % n)
2.345
print("%0.3f" % npn)  # :)
2.345

@markotoplak markotoplak merged commit 871b406 into biolab:master Nov 8, 2024
26 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Continuize: multiple attributes with the same name
3 participants