Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/warning.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Two Pytest warnings due to numpy and pytest mocker in test_dump function

**Security:**

* <news item>
2 changes: 0 additions & 2 deletions requirements/build.txt
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
python
setuptools
File renamed without changes.
1 change: 1 addition & 0 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
numpy
17 changes: 9 additions & 8 deletions tests/test_diffraction_objects.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from pathlib import Path

import numpy as np
Expand Down Expand Up @@ -232,18 +233,22 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected):


def test_dump(tmp_path, mocker):
x, y = np.linspace(0, 10, 11), np.linspace(0, 10, 11)
x, y = np.linspace(0, 5, 6), np.linspace(0, 5, 6)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To recollect our memory: we had this invalid value warning:

RuntimeWarning: invalid value encountered in arcsin
    print(np.rad2deg(2.0 * np.arcsin(q * pre_factor)))

Problem:

In our dummy test_dump function:

The code sets arbitrary q values as:

# x, y = np.linspace(0, 10, 11), np.linspace(0, 10, 11) sets q
# q = np.asarray(q)
# print(q)
[ 0.  1.  2.  3.  4.  5.  6.  7.  8.  9. 10.]

Hence, when we try to convert q to two-theta, using test.wavelength = 1.54:

print(np.rad2deg(2.0 * np.arcsin(q * pre_factor)))
[  0.          14.07850645  28.37532297  43.14126254  58.70709081
  75.57672216  94.66443973 118.15097974 157.27157928          nan
          nan]

We have nan values.

Solution:

Just simply use the valid q range from 0 to 6, etc.

directory = Path(tmp_path)
file = directory / "testfile"
test = Diffraction_object()
test.wavelength = 1.54
test.name = "test"
test.scat_quantity = "x-ray"
test.insert_scattering_quantity(
x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}}
x, y, "q", metadata={"thing1": 1, "thing2": "thing2", "package_info": {"package2": "3.4.5"}}
)
with mocker.patch("importlib.metadata.version", return_value="3.3.0"), freeze_time("2012-01-14"):

mocker.patch("importlib.metadata.version", return_value="3.3.0")

with freeze_time("2012-01-14"):
test.dump(file, "q")

with open(file, "r") as f:
actual = f.read()
expected = (
Expand All @@ -256,10 +261,6 @@ def test_dump(tmp_path, mocker):
"3.000000000000000000e+00 3.000000000000000000e+00\n"
"4.000000000000000000e+00 4.000000000000000000e+00\n"
"5.000000000000000000e+00 5.000000000000000000e+00\n"
"6.000000000000000000e+00 6.000000000000000000e+00\n"
"7.000000000000000000e+00 7.000000000000000000e+00\n"
"8.000000000000000000e+00 8.000000000000000000e+00\n"
"9.000000000000000000e+00 9.000000000000000000e+00\n"
"1.000000000000000000e+01 1.000000000000000000e+01\n"
)

assert actual == expected