Skip to content

Commit 79a2f1e

Browse files
Alison WuAlison Wu
authored andcommitted
renamed functions and files to PEP8
1 parent 6a121cc commit 79a2f1e

File tree

10 files changed

+34
-40
lines changed

10 files changed

+34
-40
lines changed

src/diffpy/utils/parsers/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,4 @@
1616
"""Various utilities related to data parsing and manipulation.
1717
"""
1818

19-
from .loaddata import loadData
20-
from .serialization import deserialize_data, serialize_data
21-
22-
# silence the pyflakes syntax checker
23-
assert loadData or True
24-
assert serialize_data or deserialize_data or True
25-
2619
# End of file
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import numpy
1717

1818

19-
def loadData(filename, minrows=10, headers=False, hdel="=", hignore=None, **kwargs):
19+
def load_data(filename, minrows=10, headers=False, hdel="=", hignore=None, **kwargs):
2020
"""Find and load data from a text file.
2121
2222
The data block is identified as the first matrix block of at least minrows rows and constant number of columns.

src/diffpy/utils/scattering_objects/diffraction_objects.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818

1919

20-
class Diffraction_object:
20+
class diffraction_object:
2121
def __init__(self, name="", wavelength=None):
2222
self.name = name
2323
self.wavelength = wavelength
@@ -29,7 +29,7 @@ def __init__(self, name="", wavelength=None):
2929
self.metadata = {}
3030

3131
def __eq__(self, other):
32-
if not isinstance(other, Diffraction_object):
32+
if not isinstance(other, diffraction_object):
3333
return NotImplemented
3434
self_attributes = [key for key in self.__dict__ if not key.startswith("_")]
3535
other_attributes = [key for key in other.__dict__ if not key.startswith("_")]
@@ -59,7 +59,7 @@ def __add__(self, other):
5959
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
6060
summed.on_tth[1] = self.on_tth[1] + other
6161
summed.on_q[1] = self.on_q[1] + other
62-
elif not isinstance(other, Diffraction_object):
62+
elif not isinstance(other, diffraction_object):
6363
raise TypeError("I only know how to sum two Diffraction_object objects")
6464
elif self.on_tth[0].all() != other.on_tth[0].all():
6565
raise RuntimeError(x_grid_emsg)
@@ -73,7 +73,7 @@ def __radd__(self, other):
7373
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
7474
summed.on_tth[1] = self.on_tth[1] + other
7575
summed.on_q[1] = self.on_q[1] + other
76-
elif not isinstance(other, Diffraction_object):
76+
elif not isinstance(other, diffraction_object):
7777
raise TypeError("I only know how to sum two Scattering_object objects")
7878
elif self.on_tth[0].all() != other.on_tth[0].all():
7979
raise RuntimeError(x_grid_emsg)
@@ -87,7 +87,7 @@ def __sub__(self, other):
8787
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
8888
subtracted.on_tth[1] = self.on_tth[1] - other
8989
subtracted.on_q[1] = self.on_q[1] - other
90-
elif not isinstance(other, Diffraction_object):
90+
elif not isinstance(other, diffraction_object):
9191
raise TypeError("I only know how to subtract two Scattering_object objects")
9292
elif self.on_tth[0].all() != other.on_tth[0].all():
9393
raise RuntimeError(x_grid_emsg)
@@ -101,7 +101,7 @@ def __rsub__(self, other):
101101
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
102102
subtracted.on_tth[1] = other - self.on_tth[1]
103103
subtracted.on_q[1] = other - self.on_q[1]
104-
elif not isinstance(other, Diffraction_object):
104+
elif not isinstance(other, diffraction_object):
105105
raise TypeError("I only know how to subtract two Scattering_object objects")
106106
elif self.on_tth[0].all() != other.on_tth[0].all():
107107
raise RuntimeError(x_grid_emsg)
@@ -115,7 +115,7 @@ def __mul__(self, other):
115115
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
116116
multiplied.on_tth[1] = other * self.on_tth[1]
117117
multiplied.on_q[1] = other * self.on_q[1]
118-
elif not isinstance(other, Diffraction_object):
118+
elif not isinstance(other, diffraction_object):
119119
raise TypeError("I only know how to multiply two Scattering_object objects")
120120
elif self.on_tth[0].all() != other.on_tth[0].all():
121121
raise RuntimeError(x_grid_emsg)
@@ -141,7 +141,7 @@ def __truediv__(self, other):
141141
if isinstance(other, int) or isinstance(other, float) or isinstance(other, np.ndarray):
142142
divided.on_tth[1] = other / self.on_tth[1]
143143
divided.on_q[1] = other / self.on_q[1]
144-
elif not isinstance(other, Diffraction_object):
144+
elif not isinstance(other, diffraction_object):
145145
raise TypeError("I only know how to multiply two Scattering_object objects")
146146
elif self.on_tth[0].all() != other.on_tth[0].all():
147147
raise RuntimeError(x_grid_emsg)

tests/test_diffraction_objects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
from freezegun import freeze_time
66

7-
from diffpy.utils.scattering_objects.diffraction_objects import Diffraction_object
7+
from diffpy.utils.scattering_objects.diffraction_objects import diffraction_object
88

99
params = [
1010
( # Default
@@ -222,8 +222,8 @@
222222

223223
@pytest.mark.parametrize("inputs1, inputs2, expected", params)
224224
def test_diffraction_objects_equality(inputs1, inputs2, expected):
225-
diffraction_object1 = Diffraction_object()
226-
diffraction_object2 = Diffraction_object()
225+
diffraction_object1 = diffraction_object()
226+
diffraction_object2 = diffraction_object()
227227
diffraction_object1_attributes = [key for key in diffraction_object1.__dict__ if not key.startswith("_")]
228228
for i, attribute in enumerate(diffraction_object1_attributes):
229229
setattr(diffraction_object1, attribute, inputs1[i])
@@ -235,7 +235,7 @@ def test_dump(tmp_path, mocker):
235235
x, y = np.linspace(0, 5, 6), np.linspace(0, 5, 6)
236236
directory = Path(tmp_path)
237237
file = directory / "testfile"
238-
test = Diffraction_object()
238+
test = diffraction_object()
239239
test.wavelength = 1.54
240240
test.name = "test"
241241
test.scat_quantity = "x-ray"

tests/test_loaddata.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy
99
import pytest
1010

11-
from diffpy.utils.parsers import loadData
11+
from diffpy.utils.parsers.data_loader import load_data
1212

1313

1414
##############################################################################
@@ -21,29 +21,29 @@ def test_loadData_default(self):
2121
"""check loadData() with default options"""
2222
loaddata01 = self.datafile("loaddata01.txt")
2323
d2c = numpy.array([[3, 31], [4, 32], [5, 33]])
24-
self.assertRaises(IOError, loadData, "doesnotexist")
24+
self.assertRaises(IOError, load_data, "doesnotexist")
2525
# the default minrows=10 makes it read from the third line
26-
d = loadData(loaddata01)
26+
d = load_data(loaddata01)
2727
self.assertTrue(numpy.array_equal(d2c, d))
2828
# the usecols=(0, 1) would make it read from the third line
29-
d = loadData(loaddata01, minrows=1, usecols=(0, 1))
29+
d = load_data(loaddata01, minrows=1, usecols=(0, 1))
3030
self.assertTrue(numpy.array_equal(d2c, d))
3131
# check the effect of usecols effect
32-
d = loadData(loaddata01, usecols=(0,))
32+
d = load_data(loaddata01, usecols=(0,))
3333
self.assertTrue(numpy.array_equal(d2c[:, 0], d))
34-
d = loadData(loaddata01, usecols=(1,))
34+
d = load_data(loaddata01, usecols=(1,))
3535
self.assertTrue(numpy.array_equal(d2c[:, 1], d))
3636
return
3737

3838
def test_loadData_1column(self):
3939
"""check loading of one-column data."""
4040
loaddata01 = self.datafile("loaddata01.txt")
4141
d1c = numpy.arange(1, 6)
42-
d = loadData(loaddata01, usecols=[0], minrows=1)
42+
d = load_data(loaddata01, usecols=[0], minrows=1)
4343
self.assertTrue(numpy.array_equal(d1c, d))
44-
d = loadData(loaddata01, usecols=[0], minrows=2)
44+
d = load_data(loaddata01, usecols=[0], minrows=2)
4545
self.assertTrue(numpy.array_equal(d1c, d))
46-
d = loadData(loaddata01, usecols=[0], minrows=3)
46+
d = load_data(loaddata01, usecols=[0], minrows=3)
4747
self.assertFalse(numpy.array_equal(d1c, d))
4848
return
4949

@@ -52,7 +52,7 @@ def test_loadData_headers(self):
5252
loaddatawithheaders = self.datafile("loaddatawithheaders.txt")
5353
hignore = ["# ", "// ", "["] # ignore lines beginning with these strings
5454
delimiter = ": " # what our data should be separated by
55-
hdata = loadData(loaddatawithheaders, headers=True, hdel=delimiter, hignore=hignore)
55+
hdata = load_data(loaddatawithheaders, headers=True, hdel=delimiter, hignore=hignore)
5656
# only fourteen lines of data are formatted properly
5757
assert len(hdata) == 14
5858
# check the following are floats

tests/test_resample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import numpy as np
22
import pytest
33

4-
from diffpy.utils.resample import wsinterp
4+
from diffpy.utils.resampler import wsinterp
55

66

77
def test_wsinterp():

tests/test_serialization.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import numpy
44
import pytest
55

6-
from diffpy.utils.parsers import deserialize_data, loadData, serialize_data
6+
from diffpy.utils.parsers.serializer import deserialize_data, serialize_data
7+
from diffpy.utils.parsers.data_loader import load_data
78
from diffpy.utils.parsers.custom_exceptions import ImproperSizeError, UnsupportedTypeError
89

910
tests_dir = os.path.dirname(os.path.abspath(locals().get("__file__", "file.py")))
@@ -20,8 +21,8 @@ def test_load_multiple(tmp_path, datafile):
2021
for hfname in tlm_list:
2122
# gather data using loadData
2223
headerfile = os.path.normpath(os.path.join(tests_dir, "testdata", "dbload", hfname))
23-
hdata = loadData(headerfile, headers=True)
24-
data_table = loadData(headerfile)
24+
hdata = load_data(headerfile, headers=True)
25+
data_table = load_data(headerfile)
2526

2627
# check path extraction
2728
generated_data = serialize_data(headerfile, hdata, data_table, dt_colnames=["r", "gr"], show_path=True)
@@ -50,8 +51,8 @@ def test_exceptions(datafile):
5051
loadfile = datafile("loadfile.txt")
5152
warningfile = datafile("generatewarnings.txt")
5253
nodt = datafile("loaddatawithheaders.txt")
53-
hdata = loadData(loadfile, headers=True)
54-
data_table = loadData(loadfile)
54+
hdata = load_data(loadfile, headers=True)
55+
data_table = load_data(loadfile)
5556

5657
# improper file types
5758
with pytest.raises(UnsupportedTypeError):
@@ -87,15 +88,15 @@ def test_exceptions(datafile):
8788
assert numpy.allclose(r_extract[data_name]["r"], r_list)
8889
assert numpy.allclose(gr_extract[data_name]["gr"], gr_list)
8990
# no datatable
90-
nodt_hdata = loadData(nodt, headers=True)
91-
nodt_dt = loadData(nodt)
91+
nodt_hdata = load_data(nodt, headers=True)
92+
nodt_dt = load_data(nodt)
9293
no_dt = serialize_data(nodt, nodt_hdata, nodt_dt, show_path=False)
9394
nodt_data_name = list(no_dt.keys())[0]
9495
assert numpy.allclose(no_dt[nodt_data_name]["data table"], nodt_dt)
9596

9697
# ensure user is warned when columns are overwritten
97-
hdata = loadData(warningfile, headers=True)
98-
data_table = loadData(warningfile)
98+
hdata = load_data(warningfile, headers=True)
99+
data_table = load_data(warningfile)
99100
with pytest.warns(RuntimeWarning) as record:
100101
serialize_data(
101102
warningfile,

0 commit comments

Comments
 (0)