Skip to content

Commit 1b89d4c

Browse files
committed
PR Review changes - Remove formatting changes, change to use np rng
1 parent f76268c commit 1b89d4c

File tree

2 files changed

+53
-85
lines changed

2 files changed

+53
-85
lines changed

benchmarks/votable.py

Lines changed: 49 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from astropy.io.votable import parse, from_table
55
from astropy.table import Table
66

7-
np.random.seed(42)
7+
rng = np.random.default_rng(42)
88

99
SMALL_SIZE = 1000
1010
LARGE_SIZE = 200000
@@ -17,18 +17,17 @@
1717
id_data = np.arange(LARGE_SIZE, dtype=np.int64)
1818
flag_data = np.random.choice([True, False], LARGE_SIZE)
1919
quality_data = np.random.randint(0, 256, LARGE_SIZE, dtype=np.uint8)
20-
bool_data = np.random.randint(0, 2, LARGE_SIZE).astype(bool)
20+
bool_data = rng.integers(0, 2, LARGE_SIZE, dtype=bool)
2121

2222
short_names = np.array([f"OBJ_{i:08d}" for i in range(LARGE_SIZE)])
23-
filter_names = np.random.choice(["u", "g", "r", "i", "z", "Y"], LARGE_SIZE)
23+
filter_names = np.random.choice(['u', 'g', 'r', 'i', 'z', 'Y'], LARGE_SIZE)
2424
classifications = np.random.choice(
25-
["STAR", "GALAXY", "QSO", "UNKNOWN"], LARGE_SIZE)
26-
long_descriptions = np.array(
27-
[
28-
f"Extend description about a field {i // 1000:04d}"
29-
for i in range(LARGE_SIZE)
30-
]
25+
['STAR', 'GALAXY', 'QSO', 'UNKNOWN'], LARGE_SIZE
3126
)
27+
long_descriptions = np.array([
28+
f"Extend description about a field {i//1000:04d}"
29+
for i in range(LARGE_SIZE)
30+
])
3231

3332

3433
def create_votable_bytes(
@@ -39,8 +38,7 @@ def create_votable_bytes(
3938
votable = from_table(table_data)
4039

4140
if bitarray_size is not None:
42-
first_table = votable.get_first_table()
43-
for field in first_table.fields:
41+
for field in votable.get_first_table().fields:
4442
if field.datatype == "bit":
4543
field.arraysize = str(bitarray_size)
4644

@@ -61,9 +59,9 @@ def setup(self):
6159
flux_data[:LARGE_SIZE],
6260
count_data[:LARGE_SIZE],
6361
id_data[:LARGE_SIZE],
64-
quality_data[:LARGE_SIZE],
62+
quality_data[:LARGE_SIZE]
6563
],
66-
names=["ra", "dec", "mag", "flux", "counts", "id", "quality"],
64+
names=['ra', 'dec', 'mag', 'flux', 'counts', 'id', 'quality']
6765
)
6866

6967
self.binary_data = create_votable_bytes(
@@ -89,13 +87,13 @@ def setup(self):
8987
short_names[:LARGE_SIZE],
9088
filter_names[:LARGE_SIZE],
9189
classifications[:LARGE_SIZE],
92-
mag_data[:LARGE_SIZE],
90+
mag_data[:LARGE_SIZE]
9391
],
94-
names=["ra", "dec", "object_id", "filter", "class", "mag"],
92+
names=['ra', 'dec', 'object_id', 'filter', 'class', 'mag']
9593
)
9694

97-
self.binary_data = create_votable_bytes(table, "binary")
98-
self.binary2_data = create_votable_bytes(table, "binary2")
95+
self.binary_data = create_votable_bytes(table, 'binary')
96+
self.binary2_data = create_votable_bytes(table, 'binary2')
9997

10098
def time_short_strings_binary(self):
10199
parse(io.BytesIO(self.binary_data))
@@ -113,13 +111,13 @@ def setup(self):
113111
ra_data[:LARGE_SIZE],
114112
dec_data[:LARGE_SIZE],
115113
long_descriptions[:LARGE_SIZE],
116-
mag_data[:LARGE_SIZE],
114+
mag_data[:LARGE_SIZE]
117115
],
118-
names=["ra", "dec", "description", "mag"],
116+
names=['ra', 'dec', 'description', 'mag']
119117
)
120118

121-
self.binary_data = create_votable_bytes(table, "binary")
122-
self.binary2_data = create_votable_bytes(table, "binary2")
119+
self.binary_data = create_votable_bytes(table, 'binary')
120+
self.binary2_data = create_votable_bytes(table, 'binary2')
123121

124122
def time_long_strings_binary(self):
125123
parse(io.BytesIO(self.binary_data))
@@ -137,25 +135,19 @@ def setup(self):
137135
short_names[:LARGE_SIZE],
138136
filter_names[:LARGE_SIZE],
139137
classifications[:LARGE_SIZE],
140-
np.random.choice(["A", "B", "C", "D"], LARGE_SIZE),
141-
np.random.choice(["HIGH", "MED", "LOW"], LARGE_SIZE),
138+
np.random.choice(['A', 'B', 'C', 'D'], LARGE_SIZE),
139+
np.random.choice(['HIGH', 'MED', 'LOW'], LARGE_SIZE),
142140
long_descriptions[:LARGE_SIZE],
143141
ra_data[:LARGE_SIZE],
144-
dec_data[:LARGE_SIZE],
142+
dec_data[:LARGE_SIZE]
145143
],
146144
names=[
147-
"id",
148-
"filter",
149-
"class",
150-
"grade",
151-
"priority",
152-
"desc",
153-
"ra",
154-
"dec",
155-
],
145+
'id', 'filter', 'class', 'grade',
146+
'priority', 'desc', 'ra', 'dec'
147+
]
156148
)
157149

158-
self.binary2_data = create_votable_bytes(table, "binary2")
150+
self.binary2_data = create_votable_bytes(table, 'binary2')
159151

160152
def time_string_intensive_binary2(self):
161153
parse(io.BytesIO(self.binary2_data))
@@ -179,21 +171,13 @@ def setup(self):
179171
np.random.choice([True, False], LARGE_SIZE),
180172
],
181173
names=[
182-
"ra",
183-
"dec",
184-
"saturated",
185-
"flagged",
186-
"edge_pixel",
187-
"cosmic_ray",
188-
"variable",
189-
"extended",
190-
"public",
191-
"calibrated",
192-
],
174+
'ra', 'dec', 'saturated', 'flagged', 'edge_pixel',
175+
'cosmic_ray', 'variable', 'extended', 'public', 'calibrated'
176+
]
193177
)
194178

195-
self.binary_data = create_votable_bytes(table, "binary")
196-
self.binary2_data = create_votable_bytes(table, "binary2")
179+
self.binary_data = create_votable_bytes(table, 'binary')
180+
self.binary2_data = create_votable_bytes(table, 'binary2')
197181

198182
def time_booleans_binary(self):
199183
parse(io.BytesIO(self.binary_data))
@@ -207,24 +191,15 @@ class TimeVOTableBitArrayOptimization:
207191

208192
def setup(self):
209193
table = Table(
210-
[
211-
ra_data[:LARGE_SIZE],
212-
dec_data[:LARGE_SIZE],
213-
mag_data[:LARGE_SIZE],
214-
np.random.randint(0, 2, LARGE_SIZE).astype(bool),
215-
np.random.randint(0, 2, LARGE_SIZE).astype(bool),
216-
np.random.randint(0, 2, LARGE_SIZE).astype(bool),
217-
np.random.randint(0, 2, LARGE_SIZE).astype(bool),
218-
],
219-
names=[
220-
"ra",
221-
"dec",
222-
"mag",
223-
"detected",
224-
"saturated",
225-
"edge_pixel",
226-
"cosmic_ray",
227-
],
194+
{
195+
"ra": ra_data[:LARGE_SIZE],
196+
"dec": dec_data[:LARGE_SIZE],
197+
"mag": mag_data[:LARGE_SIZE],
198+
"detected": rng.randint(0, 2, LARGE_SIZE).astype(bool),
199+
"saturated": rng.randint(0, 2, LARGE_SIZE).astype(bool),
200+
"edge_pixel": rng.randint(0, 2, LARGE_SIZE).astype(bool),
201+
"cosmic_ray": rng.randint(0, 2, LARGE_SIZE).astype(bool),
202+
}
228203
)
229204

230205
self.binary_bitarray_8_data = create_votable_bytes(
@@ -271,21 +246,13 @@ def setup(self):
271246
flag_data[:LARGE_SIZE],
272247
],
273248
names=[
274-
"ra",
275-
"dec",
276-
"id",
277-
"mag",
278-
"flux",
279-
"filter",
280-
"class",
281-
"counts",
282-
"quality",
283-
"detected",
284-
],
249+
'ra', 'dec', 'id', 'mag', 'flux',
250+
'filter', 'class', 'counts', 'quality', 'detected'
251+
]
285252
)
286253

287-
self.binary_data = create_votable_bytes(table, "binary")
288-
self.binary2_data = create_votable_bytes(table, "binary2")
254+
self.binary_data = create_votable_bytes(table, 'binary')
255+
self.binary2_data = create_votable_bytes(table, 'binary2')
289256

290257
def time_mixed_binary(self):
291258
parse(io.BytesIO(self.binary_data))
@@ -302,13 +269,13 @@ def setup(self):
302269
[
303270
ra_data[:SMALL_SIZE],
304271
dec_data[:SMALL_SIZE],
305-
mag_data[:SMALL_SIZE],
272+
mag_data[:SMALL_SIZE]
306273
],
307-
names=["ra", "dec", "mag"],
274+
names=['ra', 'dec', 'mag']
308275
)
309276

310-
self.binary_data = create_votable_bytes(table, "binary")
311-
self.binary2_data = create_votable_bytes(table, "binary2")
277+
self.binary_data = create_votable_bytes(table, 'binary')
278+
self.binary2_data = create_votable_bytes(table, 'binary2')
312279

313280
def time_small_binary(self):
314281
parse(io.BytesIO(self.binary_data))

benchmarks/votable_converters.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ class TimeBitArrayConverters:
1010
"""Direct converter function benchmarks."""
1111

1212
def setup(self):
13+
rng = np.random.default_rng(42)
1314

14-
self.small_bool = np.random.randint(0, 2, SMALL_SIZE).astype(bool)
15-
self.large_bool = np.random.randint(0, 2, LARGE_SIZE).astype(bool)
15+
self.small_bool = rng.integers(0, 2, SMALL_SIZE, dtype=bool)
16+
self.large_bool = rng.integers(0, 2, LARGE_SIZE, dtype=bool)
1617

17-
mask = np.random.random(LARGE_SIZE) < 0.2
18+
mask = rng.random(LARGE_SIZE) < 0.2
1819
self.masked_bool = ma.array(self.large_bool, mask=mask)
1920

2021
self.small_bits = bool_to_bitarray(self.small_bool)

0 commit comments

Comments
 (0)