Skip to content

Commit 62441df

Browse files
neutrinoceroscphyc
authored andcommitted
STY: apply autofixes for RUF031
1 parent ff68fe3 commit 62441df

File tree

10 files changed

+57
-66
lines changed

10 files changed

+57
-66
lines changed

yt/data_objects/tests/test_derived_quantities.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_average():
6868
("gas", "density"), ("gas", "cell_mass")
6969
)
7070
a_mean = (ad["gas", "density"] * ad["gas", "cell_mass"]).sum() / ad[
71-
("gas", "cell_mass")
71+
"gas", "cell_mass"
7272
].sum()
7373
assert_rel_equal(my_mean, a_mean, 12)
7474

@@ -87,7 +87,7 @@ def test_standard_deviation():
8787
("gas", "density"), ("gas", "cell_mass")
8888
)
8989
a_mean = (ad["gas", "density"] * ad["gas", "cell_mass"]).sum() / ad[
90-
("gas", "cell_mass")
90+
"gas", "cell_mass"
9191
].sum()
9292
assert_rel_equal(my_mean, a_mean, 12)
9393
a_std = np.sqrt(

yt/data_objects/tests/test_particle_trajectories_pytest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def dummy(pfilter, data):
122122
@pytest.mark.parametrize("ptype", [None, "io"])
123123
def test_default_field_tuple(particle_trajectories_test_dataset, ptype):
124124
ds = particle_trajectories_test_dataset[0]
125-
ids = ds.all_data()[("all", "particle_index")]
125+
ids = ds.all_data()["all", "particle_index"]
126126
trajs = particle_trajectories_test_dataset.particle_trajectories(
127127
ids, ptype=ptype, suppress_logging=True
128128
)
@@ -138,7 +138,7 @@ def test_default_field_tuple(particle_trajectories_test_dataset, ptype):
138138
@pytest.mark.parametrize("ptype", [None, "io"])
139139
def test_time_and_index(particle_trajectories_test_dataset, ptype):
140140
ds = particle_trajectories_test_dataset[0]
141-
ids = ds.all_data()[("all", "particle_index")]
141+
ids = ds.all_data()["all", "particle_index"]
142142
trajs = particle_trajectories_test_dataset.particle_trajectories(
143143
ids, ptype=ptype, suppress_logging=True
144144
)

yt/data_objects/tests/test_rays.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ def test_ray_particle2():
110110
# restricts you to 4 -- 5 digits precision
111111
assert_equal(ray0["t"].shape, (1,))
112112
assert_rel_equal(ray0["t"], np.array([0.5]), 5)
113-
assert_rel_equal(ray0[("gas", "position")].v, np.array([[0.5, 0.5, 0.5]]), 5)
113+
assert_rel_equal(ray0["gas", "position"].v, np.array([[0.5, 0.5, 0.5]]), 5)
114114
dl0 = integrate_kernel(kernelfunc, b0, hsml0)
115-
dl0 *= ray0[("gas", "mass")].v / ray0[("gas", "density")].v
115+
dl0 *= ray0["gas", "mass"].v / ray0["gas", "density"].v
116116
assert_rel_equal(ray0[("dts")].v, dl0 / len0, 4)
117117

118118
## Ray in the middle of the box:
@@ -133,10 +133,10 @@ def test_ray_particle2():
133133
assert_equal(ray1["t"].shape, (2,))
134134
assert_rel_equal(ray1["t"], np.array([0.25, 0.75]), 5)
135135
assert_rel_equal(
136-
ray1[("gas", "position")].v, np.array([[1.5, 0.5, 1.5], [1.5, 0.5, 2.5]]), 5
136+
ray1["gas", "position"].v, np.array([[1.5, 0.5, 1.5], [1.5, 0.5, 2.5]]), 5
137137
)
138138
dl1 = integrate_kernel(kernelfunc, b1, hsml1)
139-
dl1 *= ray1[("gas", "mass")].v / ray1[("gas", "density")].v
139+
dl1 *= ray1["gas", "mass"].v / ray1["gas", "density"].v
140140
assert_rel_equal(ray1[("dts")].v, dl1 / len1, 4)
141141

142142
## Ray missing all particles:
@@ -150,4 +150,4 @@ def test_ray_particle2():
150150
ray2.field_data["dts"] = ray2.ds.arr(ray2._generate_container_field_sph("dts"))
151151
assert_equal(ray2["t"].shape, (0,))
152152
assert_equal(ray2["dts"].shape, (0,))
153-
assert_equal(ray2[("gas", "position")].v.shape, (0, 3))
153+
assert_equal(ray2["gas", "position"].v.shape, (0, 3))

yt/frontends/amrex/tests/test_outputs.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ def test_nyx_particle_io():
9797

9898
grid = ds.index.grids[0]
9999
npart_grid_0 = 7908 # read directly from the header
100-
assert_equal(grid[("all", "particle_position_x")].size, npart_grid_0)
100+
assert_equal(grid["all", "particle_position_x"].size, npart_grid_0)
101101
assert_equal(grid["DM", "particle_position_y"].size, npart_grid_0)
102102
assert_equal(grid["all", "particle_position_z"].size, npart_grid_0)
103103

104104
ad = ds.all_data()
105105
npart = 32768 # read directly from the header
106-
assert_equal(ad[("all", "particle_velocity_x")].size, npart)
106+
assert_equal(ad["all", "particle_velocity_x"].size, npart)
107107
assert_equal(ad["DM", "particle_velocity_y"].size, npart)
108108
assert_equal(ad["all", "particle_velocity_z"].size, npart)
109109

110-
assert np.all(ad[("all", "particle_mass")] == ad[("all", "particle_mass")][0])
110+
assert np.all(ad["all", "particle_mass"] == ad["all", "particle_mass"][0])
111111

112112
left_edge = ds.arr([0.0, 0.0, 0.0], "code_length")
113113
right_edge = ds.arr([4.0, 4.0, 4.0], "code_length")
@@ -117,22 +117,22 @@ def test_nyx_particle_io():
117117

118118
assert np.all(
119119
np.logical_and(
120-
reg[("all", "particle_position_x")] <= right_edge[0],
121-
reg[("all", "particle_position_x")] >= left_edge[0],
120+
reg["all", "particle_position_x"] <= right_edge[0],
121+
reg["all", "particle_position_x"] >= left_edge[0],
122122
)
123123
)
124124

125125
assert np.all(
126126
np.logical_and(
127-
reg[("all", "particle_position_y")] <= right_edge[1],
128-
reg[("all", "particle_position_y")] >= left_edge[1],
127+
reg["all", "particle_position_y"] <= right_edge[1],
128+
reg["all", "particle_position_y"] >= left_edge[1],
129129
)
130130
)
131131

132132
assert np.all(
133133
np.logical_and(
134-
reg[("all", "particle_position_z")] <= right_edge[2],
135-
reg[("all", "particle_position_z")] >= left_edge[2],
134+
reg["all", "particle_position_z"] <= right_edge[2],
135+
reg["all", "particle_position_z"] >= left_edge[2],
136136
)
137137
)
138138

@@ -155,13 +155,13 @@ def test_castro_particle_io():
155155

156156
grid = ds.index.grids[2]
157157
npart_grid_2 = 49 # read directly from the header
158-
assert_equal(grid[("all", "particle_position_x")].size, npart_grid_2)
158+
assert_equal(grid["all", "particle_position_x"].size, npart_grid_2)
159159
assert_equal(grid["Tracer", "particle_position_y"].size, npart_grid_2)
160160
assert_equal(grid["all", "particle_position_y"].size, npart_grid_2)
161161

162162
ad = ds.all_data()
163163
npart = 49 # read directly from the header
164-
assert_equal(ad[("all", "particle_velocity_x")].size, npart)
164+
assert_equal(ad["all", "particle_velocity_x"].size, npart)
165165
assert_equal(ad["Tracer", "particle_velocity_y"].size, npart)
166166
assert_equal(ad["all", "particle_velocity_y"].size, npart)
167167

@@ -173,15 +173,15 @@ def test_castro_particle_io():
173173

174174
assert np.all(
175175
np.logical_and(
176-
reg[("all", "particle_position_x")] <= right_edge[0],
177-
reg[("all", "particle_position_x")] >= left_edge[0],
176+
reg["all", "particle_position_x"] <= right_edge[0],
177+
reg["all", "particle_position_x"] >= left_edge[0],
178178
)
179179
)
180180

181181
assert np.all(
182182
np.logical_and(
183-
reg[("all", "particle_position_y")] <= right_edge[1],
184-
reg[("all", "particle_position_y")] >= left_edge[1],
183+
reg["all", "particle_position_y"] <= right_edge[1],
184+
reg["all", "particle_position_y"] >= left_edge[1],
185185
)
186186
)
187187

@@ -265,22 +265,22 @@ def test_warpx_particle_io():
265265

266266
assert np.all(
267267
np.logical_and(
268-
reg[("all", "particle_position_x")] <= right_edge[0],
269-
reg[("all", "particle_position_x")] >= left_edge[0],
268+
reg["all", "particle_position_x"] <= right_edge[0],
269+
reg["all", "particle_position_x"] >= left_edge[0],
270270
)
271271
)
272272

273273
assert np.all(
274274
np.logical_and(
275-
reg[("all", "particle_position_y")] <= right_edge[1],
276-
reg[("all", "particle_position_y")] >= left_edge[1],
275+
reg["all", "particle_position_y"] <= right_edge[1],
276+
reg["all", "particle_position_y"] >= left_edge[1],
277277
)
278278
)
279279

280280
assert np.all(
281281
np.logical_and(
282-
reg[("all", "particle_position_z")] <= right_edge[2],
283-
reg[("all", "particle_position_z")] >= left_edge[2],
282+
reg["all", "particle_position_z"] <= right_edge[2],
283+
reg["all", "particle_position_z"] >= left_edge[2],
284284
)
285285
)
286286

yt/frontends/parthenon/tests/test_outputs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def field_func(name):
5050
# reading data of two fields and compare against each other (data is squared in output)
5151
ad = ds.all_data()
5252
assert_allclose(
53-
ad[("parthenon", "one_minus_advected")] ** 2.0,
54-
ad[("parthenon", "one_minus_advected_sq")],
53+
ad["parthenon", "one_minus_advected"] ** 2.0,
54+
ad["parthenon", "one_minus_advected_sq"],
5555
)
5656

5757
# check if the peak is in the domain center (and at the highest refinement level)

yt/frontends/stream/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def _yield_coordinates(self, data_file, needed_ptype=None):
161161
pos = np.column_stack(
162162
[
163163
self.fields[data_file.filename][
164-
(ptype, f"particle_position_{ax}")
164+
ptype, f"particle_position_{ax}"
165165
]
166166
for ax in "xyz"
167167
]

yt/frontends/stream/tests/test_stream_stretched.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_cell_width_type(data_cell_widths_N16):
8787
cell_widths=cell_widths,
8888
)
8989

90-
_ = ds.slice(0, ds.domain_center[0])[("stream", "density")]
90+
_ = ds.slice(0, ds.domain_center[0])["stream", "density"]
9191

9292

9393
def test_cell_width_dimensionality(data_cell_widths_N16):

yt/geometry/coordinates/geographic_coordinates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def _dlatitude_to_dtheta(field, data):
160160

161161
def _longitude_to_phi(field, data):
162162
# longitude runs from -180 to 180
163-
lonvals = data[("index", "longitude")]
163+
lonvals = data["index", "longitude"]
164164
neglons = lonvals < 0.0
165165
if np.any(neglons):
166166
lonvals[neglons] = lonvals[neglons] + 360.0

yt/geometry/coordinates/tests/test_sph_pixelization_pytestonly.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def makemasses(i, j, k):
113113
center=center,
114114
data_source=source,
115115
)
116-
img = prj.frb.data[("gas", "density")]
116+
img = prj.frb.data["gas", "density"]
117117
if weighted:
118118
expected_out = np.zeros(
119119
(
@@ -240,7 +240,7 @@ def makemasses(i, j, k):
240240
buff_size=(outgridsize,) * 2,
241241
center=(_center, "cm"),
242242
)
243-
img = slc.frb.data[("gas", "density")]
243+
img = slc.frb.data["gas", "density"]
244244

245245
# center is same in non-projection coords
246246
if axis == 0:
@@ -272,9 +272,9 @@ def makemasses(i, j, k):
272272
ad = ds.all_data()
273273
sphcoords = np.array(
274274
[
275-
(ad[("gas", "x")]).to("cm"),
276-
(ad[("gas", "y")]).to("cm"),
277-
(ad[("gas", "z")]).to("cm"),
275+
(ad["gas", "x"]).to("cm"),
276+
(ad["gas", "y"]).to("cm"),
277+
(ad["gas", "z"]).to("cm"),
278278
]
279279
).T
280280
# print("sphcoords:")
@@ -289,15 +289,12 @@ def makemasses(i, j, k):
289289
)
290290
# print("dists <= 1:")
291291
# print(dists <= 1)
292-
sml = (ad[("gas", "smoothing_length")]).to("cm")
292+
sml = (ad["gas", "smoothing_length"]).to("cm")
293293
normkern = cubicspline_python(dists / sml.v[np.newaxis, :])
294-
sphcontr = normkern / sml[np.newaxis, :] ** 3 * ad[("gas", "mass")]
294+
sphcontr = normkern / sml[np.newaxis, :] ** 3 * ad["gas", "mass"]
295295
contsum = np.sum(sphcontr, axis=1)
296296
sphweights = (
297-
normkern
298-
/ sml[np.newaxis, :] ** 3
299-
* ad[("gas", "mass")]
300-
/ ad[("gas", "density")]
297+
normkern / sml[np.newaxis, :] ** 3 * ad["gas", "mass"] / ad["gas", "density"]
301298
)
302299
weights = np.sum(sphweights, axis=1)
303300
nzeromask = np.logical_not(weights == 0)
@@ -406,7 +403,7 @@ def makemasses(i, j, k):
406403
center=(_center, "cm"),
407404
north_vector=e2dir,
408405
)
409-
img = slc.frb.data[("gas", "density")]
406+
img = slc.frb.data["gas", "density"]
410407

411408
# center is same in x/y (e3dir/e2dir)
412409
gridcenx = (
@@ -434,9 +431,9 @@ def makemasses(i, j, k):
434431
ad = ds.all_data()
435432
sphcoords = np.array(
436433
[
437-
(ad[("gas", "x")]).to("cm"),
438-
(ad[("gas", "y")]).to("cm"),
439-
(ad[("gas", "z")]).to("cm"),
434+
(ad["gas", "x"]).to("cm"),
435+
(ad["gas", "y"]).to("cm"),
436+
(ad["gas", "z"]).to("cm"),
440437
]
441438
).T
442439
dists = distancematrix(
@@ -445,15 +442,12 @@ def makemasses(i, j, k):
445442
periodic=(periodic,) * 3,
446443
periods=np.array([3.0, 3.0, 3.0]),
447444
)
448-
sml = (ad[("gas", "smoothing_length")]).to("cm")
445+
sml = (ad["gas", "smoothing_length"]).to("cm")
449446
normkern = cubicspline_python(dists / sml.v[np.newaxis, :])
450-
sphcontr = normkern / sml[np.newaxis, :] ** 3 * ad[("gas", "mass")]
447+
sphcontr = normkern / sml[np.newaxis, :] ** 3 * ad["gas", "mass"]
451448
contsum = np.sum(sphcontr, axis=1)
452449
sphweights = (
453-
normkern
454-
/ sml[np.newaxis, :] ** 3
455-
* ad[("gas", "mass")]
456-
/ ad[("gas", "density")]
450+
normkern / sml[np.newaxis, :] ** 3 * ad["gas", "mass"] / ad["gas", "density"]
457451
)
458452
weights = np.sum(sphweights, axis=1)
459453
nzeromask = np.logical_not(weights == 0)
@@ -509,9 +503,9 @@ def test_sph_grid(
509503
ad = ds.all_data()
510504
sphcoords = np.array(
511505
[
512-
(ad[("gas", "x")]).to("cm"),
513-
(ad[("gas", "y")]).to("cm"),
514-
(ad[("gas", "z")]).to("cm"),
506+
(ad["gas", "x"]).to("cm"),
507+
(ad["gas", "y"]).to("cm"),
508+
(ad["gas", "z"]).to("cm"),
515509
]
516510
).T
517511
gridx, gridy, gridz = np.meshgrid(xcens, ycens, zcens, indexing="ij")
@@ -522,15 +516,12 @@ def test_sph_grid(
522516
gridcoords = np.array([gridx, gridy, gridz]).T
523517
periods = bbox[:, 1] - bbox[:, 0]
524518
dists = distancematrix(gridcoords, sphcoords, periodic=periodic, periods=periods)
525-
sml = (ad[("gas", "smoothing_length")]).to("cm")
519+
sml = (ad["gas", "smoothing_length"]).to("cm")
526520
normkern = cubicspline_python(dists / sml.v[np.newaxis, :])
527-
sphcontr = normkern / sml[np.newaxis, :] ** 3 * ad[("gas", "mass")]
521+
sphcontr = normkern / sml[np.newaxis, :] ** 3 * ad["gas", "mass"]
528522
contsum = np.sum(sphcontr, axis=1)
529523
sphweights = (
530-
normkern
531-
/ sml[np.newaxis, :] ** 3
532-
* ad[("gas", "mass")]
533-
/ ad[("gas", "density")]
524+
normkern / sml[np.newaxis, :] ** 3 * ad["gas", "mass"] / ad["gas", "density"]
534525
)
535526
weights = np.sum(sphweights, axis=1)
536527
nzeromask = np.logical_not(weights == 0)

yt/visualization/tests/test_offaxisprojection_pytestonly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def makemasses(i, j, k):
125125
north_vector=northvector,
126126
depth=depth,
127127
)
128-
img = prj.frb.data[("gas", "density")]
128+
img = prj.frb.data["gas", "density"]
129129
if weighted:
130130
# periodic shifts will modify the (relative) dl values a bit
131131
expected_out = np.zeros(

0 commit comments

Comments
 (0)