Data type issue in freud.kspace.AnalyzeSFactor3D class

Issue #148 resolved
Paul Chery created an issue

When I call the getSvsQ and getPeakList functions from the freud.kspace.AnalyzeSFactor3D class, I get errors. I think the code is expecting an integer instead of a float for the self.g variable.

For the getSvsQ function I get the following error: 'float' object cannot be interpreted as an integer

For the getPeakList function I get the following error: Cannot cast ufunc subtract output from dtype('float64') to dtype('int64') with casting rule 'same_kind'

I believe this error may come from the value of self.g, which should be an integer instead of a float. In the init function for the freud.kspace.AnalyzeSFactor3D class, self.g = self.grid/2, which makes self.g a float. However, self.g is used later as a parameter in the range function, which only takes integers as input.

I am using Freud version 0.6.2 with python 3.6.

Thank you

Comments (9)

  1. Paul Chery reporter

    I attached a jupyter notebook to test the error. The errors occur on lines 171, 172, 173 for the getPeakList function, and on line 205 for the getSvsQ function.

  2. Bradley Dice

    Thanks for reporting this issue, @pchery! I have submitted a pull request fix where we replace self.g = self.grid / 2 with self.g = self.grid // 2.

    This probably came about from code written for Python 2, where the default behavior of division / is integer division. This would have produced the intended result (which ignores the extra "0.5"). By explicitly using //, we get integer division in a way that is compatible with Python 3.

  3. Log in to comment