Skip to content

Commit

Permalink
ruff C4
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadair committed Mar 6, 2024
1 parent 83de1d6 commit 631496b
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exclude = [
"__pycache__",
"build",
]
select = ["E", "W", "F", "UP", "I"]
select = ["F", "E", "W", "UP", "I", "C4"]
extend-ignore = [
# pycodestyle (E, W)
"E501", # LineTooLong # TODO! fix
Expand Down
6 changes: 3 additions & 3 deletions dkist/dataset/tests/test_load_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_load_single_dataset(fixture_finder):
def test_load_multiple(fixture_finder):
datasets = load_dataset(fixture_finder)
assert isinstance(datasets, list)
assert all([isinstance(ds, Dataset) for ds in datasets])
assert all(isinstance(ds, Dataset) for ds in datasets)


def test_load_from_results(asdf_path, asdf_str):
Expand All @@ -82,14 +82,14 @@ def test_load_from_results(asdf_path, asdf_str):
res = Results([asdf_str, asdf_str])
ds = load_dataset(res)
assert isinstance(ds, list)
assert all([isinstance(ds, Dataset) for ds in ds])
assert all(isinstance(ds, Dataset) for ds in ds)


def test_multiple_from_dir(multiple_asdf_in_folder):
ds = load_dataset(multiple_asdf_in_folder)
assert isinstance(ds, list)
assert len(ds) == 2
assert all([isinstance(d, Dataset) for d in ds])
assert all(isinstance(d, Dataset) for d in ds)


def test_tiled_dataset(asdf_tileddataset_path):
Expand Down
6 changes: 3 additions & 3 deletions dkist/dataset/tests/test_tiled_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def test_tiled_dataset(simple_tiled_dataset, dataset):
assert isinstance(simple_tiled_dataset, TiledDataset)
assert simple_tiled_dataset._data[0, 0] in simple_tiled_dataset
assert 5 not in simple_tiled_dataset
assert all([isinstance(t, Dataset) for t in simple_tiled_dataset.flat])
assert all([t.shape == (2,) for t in simple_tiled_dataset])
assert all(isinstance(t, Dataset) for t in simple_tiled_dataset.flat)
assert all(t.shape == (2,) for t in simple_tiled_dataset)
assert simple_tiled_dataset.inventory is dataset.meta['inventory']
assert simple_tiled_dataset.shape == (2, 2)

Expand Down Expand Up @@ -54,7 +54,7 @@ def test_tiled_dataset_from_components(dataset):
tiled_ds = TiledDataset._from_components(shape, file_managers, wcses, header_tables, inventory)
assert isinstance(tiled_ds, TiledDataset)
assert tiled_ds.shape == shape
assert all([isinstance(t, Dataset) for t in tiled_ds.flat])
assert all(isinstance(t, Dataset) for t in tiled_ds.flat)
for ds, fm, headers in zip(tiled_ds.flat, file_managers, header_tables):
assert ds.files == fm
assert ds.meta['inventory'] is inventory
Expand Down
2 changes: 1 addition & 1 deletion dkist/dataset/tiled_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, dataset_array, inventory=None):
self._validate_component_datasets(self._data, inventory)

def __contains__(self, x):
return any([ele is x for ele in self._data.flat])
return any(ele is x for ele in self._data.flat)

def __len__(self):
return self._data.__len__()
Expand Down
2 changes: 1 addition & 1 deletion dkist/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DKISTLogger(logging.Logger):

def __init__(self, name, level=logging.NOTSET, *, capture_warning_classes=None):
super().__init__(name, level=level)
self.capture_warning_classes = tuple(capture_warning_classes) if capture_warning_classes is not None else tuple()
self.capture_warning_classes = tuple(capture_warning_classes) if capture_warning_classes is not None else ()

self.enable_warnings_capture()

Expand Down
2 changes: 1 addition & 1 deletion dkist/net/attr_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def create_from_or(wlk, tree):

@walker.add_creator(AttrAnd, DataAttr)
def create_new_param(wlk, tree):
params = dict()
params = {}

# Use the apply dispatcher to convert the attrs to their query parameters
wlk.apply(tree, params)
Expand Down
4 changes: 2 additions & 2 deletions dkist/net/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _process_table(results: "DKISTQueryResponseTable") -> "DKISTQueryResponseTab
for colname in times:
if colname not in results.colnames:
continue # pragma: no cover
if not any([v is None for v in results[colname]]):
if not any(v is None for v in results[colname]):
results[colname] = Time(results[colname])

for colname, unit in units.items():
Expand Down Expand Up @@ -241,7 +241,7 @@ def _can_handle_query(cls, *query) -> bool:
supported = set(walker.applymm.registry)
# This function is only called with arguments of the query where they are assumed to be ANDed.
supported.remove(attr.AttrAnd)
query_attrs = set(type(x) for x in query)
query_attrs = {type(x) for x in query}

# The DKIST client only requires that one or more of the support attrs be present.
if not query_attrs.issubset(supported) or len(query_attrs.intersection(supported)) < 1:
Expand Down
4 changes: 2 additions & 2 deletions dkist/net/globus/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ def test_directory_listing(mocker, transfer_client, ls_response):
return_value=ls_response)

ls = get_directory_listing("/")
assert all([isinstance(a, pathlib.Path) for a in ls])
assert all(isinstance(a, pathlib.Path) for a in ls)
assert len(ls) == 13

ls = get_directory_listing("/", "1234")
assert all([isinstance(a, pathlib.Path) for a in ls])
assert all(isinstance(a, pathlib.Path) for a in ls)
assert len(ls) == 13


Expand Down
11 changes: 5 additions & 6 deletions dkist/net/globus/tests/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ def test_process_event_list(transfer_client, mock_task_event_list):
message_events) = _process_task_events("1234", set(), transfer_client)

assert isinstance(events, set)
assert all([isinstance(e, tuple) for e in events])
assert all([all([isinstance(item, tuple) for item in e]) for e in events])
assert all(isinstance(e, tuple) for e in events)
assert all(all(isinstance(item, tuple) for item in e) for e in events)

print(events)
assert len(json_events) == 1
Expand All @@ -135,17 +135,16 @@ def test_process_event_list(transfer_client, mock_task_event_list):

def test_process_event_list_message_only(transfer_client, mock_task_event_list):
# Filter out the json event
prev_events = tuple(map(lambda x: tuple(x.items()),
mock_task_event_list.return_value))
prev_events = tuple(tuple(x.items()) for x in mock_task_event_list.return_value)
prev_events = set(prev_events[0:1])

(events,
json_events,
message_events) = _process_task_events("1234", prev_events, transfer_client)

assert isinstance(events, set)
assert all([isinstance(e, tuple) for e in events])
assert all([all([isinstance(item, tuple) for item in e]) for e in events])
assert all(isinstance(e, tuple) for e in events)
assert all(all(isinstance(item, tuple) for item in e) for e in events)

assert len(json_events) == 0
assert isinstance(json_events, tuple)
Expand Down
5 changes: 2 additions & 3 deletions dkist/net/globus/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ def _process_task_events(task_id, prev_events, tfr_client):
"""

# Convert all the events into a (key, value) tuple pair
events = set(map(lambda x: tuple(x.items()),
tfr_client.task_event_list(task_id)))
events = {tuple(x.items()) for x in tfr_client.task_event_list(task_id)}
# Drop all events we have seen before
new_events = events.difference(prev_events)

Expand All @@ -158,7 +157,7 @@ def json_loader(x):
if json_events:
json_events = tuple(map(dict, map(json_loader, map(dict, json_events))))
else:
json_events = tuple()
json_events = ()

return events, json_events, message_events

Expand Down
2 changes: 1 addition & 1 deletion dkist/net/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def api_param_names():
a.Instrument: ('instrumentNames',),
a.Wavelength: ('wavelengthRanges',),
a.Physobs: ('hasAllStokes',),
a.Provider: tuple(),
a.Provider: (),
da.Dataset: ('datasetIds',),
da.WavelengthBand: ('filterWavelengths',),
da.Observable: ('observables',),
Expand Down
2 changes: 1 addition & 1 deletion dkist/net/tests/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_registered_values():

def _generate_from_register_values(attr_type):
possible_values = get_registered_values()[attr_type]
possible_values = list(map(lambda x: x[0], possible_values))
possible_values = [x[0] for x in possible_values]

return st.builds(attr_type, st.sampled_from(possible_values))

Expand Down
6 changes: 3 additions & 3 deletions dkist/net/tests/test_attr_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_boundingbox(search, search_type, boundingbox_param):

out = walker.create(bb_query)
assert len(out) == 1
assert all([isinstance(a, dict) for a in out])
assert all(isinstance(a, dict) for a in out)

# can't verify exact coordinates, they change a bit
for key in out[0].keys():
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_and_simple(query_and_simple):
out = walker.create(query_and_simple)
assert len(out) == 1
assert isinstance(out, list)
assert all([isinstance(a, dict) for a in out])
assert all(isinstance(a, dict) for a in out)

assert out == [
{
Expand All @@ -176,7 +176,7 @@ def test_or_instrument(query_or_instrument):
out = walker.create(query_or_instrument)
assert len(out) == 2
assert isinstance(out, list)
assert all([isinstance(a, dict) for a in out])
assert all(isinstance(a, dict) for a in out)

assert out == [
{
Expand Down
2 changes: 1 addition & 1 deletion dkist/net/tests/test_attrs_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ def test_get_search_attrs_values(mocker, caplog_dkist, values_in_home, user_file

assert isinstance(attr_values, dict)
# Test that some known attrs are in the result
assert set((a.Instrument, a.dkist.HeaderVersion, a.dkist.WorkflowName)).issubset(attr_values.keys())
assert {a.Instrument, a.dkist.HeaderVersion, a.dkist.WorkflowName}.issubset(attr_values.keys())
2 changes: 1 addition & 1 deletion dkist/net/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def test_can_handle_query(client, query):
a.Level(2),
(a.Instrument("VBI"), a.Level(0)),
(a.Instrument("VBI"), a.Detector("test")),
tuple(),
(),
))
def test_cant_handle_query(client, query):
"""Some examples of invalid queries."""
Expand Down
20 changes: 10 additions & 10 deletions dkist/wcs/tests/test_coupled_compound_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ def test_coupled_sep_2d_extra(vct_2d_pc, linear_time):
def test_coupled_slit_no_repeat(linear_time):
pc_table = [rotation_matrix(a)[:2, :2] for a in np.linspace(0, 90, 10)] * u.pix

kwargs = dict(crpix=(5, 5) * u.pix,
cdelt=(1, 1) * u.arcsec/u.pix,
crval_table=(0, 0) * u.arcsec,
lon_pole=180 * u.deg,
slit=1)
kwargs = {"crpix": (5, 5) * u.pix,
"cdelt": (1, 1) * u.arcsec/u.pix,
"crval_table": (0, 0) * u.arcsec,
"lon_pole": 180 * u.deg,
"slit": 1}

vct_slit = varying_celestial_transform_from_tables(pc_table=pc_table, **kwargs)

Expand All @@ -156,11 +156,11 @@ def test_coupled_slit_with_repeat(linear_time):
pc_table = [rotation_matrix(a)[:2, :2] for a in np.linspace(0, 90, 15)] * u.pix
pc_table = pc_table.reshape((5, 3, 2, 2))

kwargs = dict(crpix=(5, 5) * u.pix,
cdelt=(1, 1) * u.arcsec/u.pix,
crval_table=(0, 0) * u.arcsec,
lon_pole=180 * u.deg,
slit=1)
kwargs = {"crpix": (5, 5) * u.pix,
"cdelt": (1, 1) * u.arcsec/u.pix,
"crval_table": (0, 0) * u.arcsec,
"lon_pole": 180 * u.deg,
"slit": 1}

vct_slit = varying_celestial_transform_from_tables(pc_table=pc_table, **kwargs)

Expand Down
24 changes: 12 additions & 12 deletions dkist/wcs/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ def test_vct_dispatch():
varying_matrix_lt = varying_matrix_lt.reshape((2, 2, 2, 2, 2, 2))
crval_table = list(zip(np.arange(1, 17), np.arange(17, 33))) * u.arcsec
crval_table = crval_table.reshape((2, 2, 2, 2, 2))
kwargs = dict(
crpix=(5, 5) * u.pix,
cdelt=(1, 1) * u.arcsec/u.pix,
lon_pole=180 * u.deg,
)
kwargs = {
"crpix": (5, 5) * u.pix,
"cdelt": (1, 1) * u.arcsec/u.pix,
"lon_pole": 180 * u.deg,
}

vct = varying_celestial_transform_from_tables(
pc_table=varying_matrix_lt[0, 0, 0],
Expand Down Expand Up @@ -348,11 +348,11 @@ def test_vct_shape_errors():
crval_table = list(zip(np.arange(1, 16), np.arange(16, 31))) * u.arcsec
crval_table = crval_table.reshape((5, 3, 2))

kwargs = dict(
crpix=(5, 5) * u.pix,
cdelt=(1, 1) * u.arcsec/u.pix,
lon_pole=180 * u.deg,
)
kwargs = {
"crpix": (5, 5) * u.pix,
"cdelt": (1, 1) * u.arcsec/u.pix,
"lon_pole": 180 * u.deg,
}

with pytest.raises(ValueError, match="only be constructed with a one dimensional"):
VaryingCelestialTransform(crval_table=crval_table, pc_table=pc_table, **kwargs)
Expand Down Expand Up @@ -454,7 +454,7 @@ def test_vct(has_units, slit, num_varying_axes):

# grid2 has coordinates outside the lut boundaries and should have nans
world2 = vct(*grid2)
assert np.any(np.isnan([item for item in world2]))
assert np.any(np.isnan(list(world2)))


def _evaluate_ravel(array_shape, inputs, order="C"):
Expand Down Expand Up @@ -483,7 +483,7 @@ def _evaluate_unravel(array_shape, index, order="C"):
curr_offset = index
# This if test is to handle multidimensional inputs properly
if isinstance(index, np.ndarray):
output_shape = tuple([len(array_shape), len(index)])
output_shape = (len(array_shape), len(index))
else:
output_shape = len(array_shape)
indices = np.zeros(output_shape, dtype=float)
Expand Down

0 comments on commit 631496b

Please sign in to comment.