Skip to content

Commit

Permalink
Fixed ruff rule-C408 violations in Astropy/io sub-package and Updated…
Browse files Browse the repository at this point in the history
… .ruff.toml
  • Loading branch information
Mubin17 committed May 25, 2023
1 parent 5b771e3 commit 7c83005
Show file tree
Hide file tree
Showing 17 changed files with 227 additions and 223 deletions.
31 changes: 15 additions & 16 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ ignore = [
# flake8-comprehensions (C4)
"C400", # unnecessary-generator-list
"C406", # unnecessary-literal-dict
"C408", # unnecessary-collection-call
"C413", # unnecessary-call-around-sorted
"C416", # unnecessary-comprehension
"C414", # unnecessary-double-cast-or-process
Expand Down Expand Up @@ -285,26 +284,26 @@ unfixable = [
# When a general exclusion is being fixed, but it affects many subpackages, it
# is better to fix for subpackages individually. The general exclusion should be
# copied to these subpackage sections and fixed there.
"astropy/__init__.py" = []
"astropy/__init__.py" = ["C408"]
"astropy/config/*" = []
"astropy/constants/*" = []
"astropy/convolution/*" = ["I001"]
"astropy/coordinates/*" = ["I001"]
"astropy/cosmology/*" = []
"astropy/coordinates/*" = ["I001", "C408"]
"astropy/cosmology/*" = ["C408"]
"astropy/io/*" = ["I001"]
"astropy/logger.py" = []
"astropy/modeling/*" = ["I001"]
"astropy/nddata/*" = ["I001"]
"astropy/logger.py" = ["C408"]
"astropy/modeling/*" = ["I001", "C408"]
"astropy/nddata/*" = ["I001", "C408"]
"astropy/samp/*" = []
"astropy/stats/*" = ["I001"]
"astropy/table/*" = ["I001"]
"astropy/tests/*" = []
"astropy/time/*" = ["I001"]
"astropy/timeseries/*" = ["I001"]
"astropy/units/*" = ["I001"]
"astropy/uncertainty/*" = []
"astropy/utils/*" = []
"astropy/visualization/*" = ["I001"]
"astropy/wcs/*" = ["I001"]
"astropy/table/*" = ["I001", "C408"]
"astropy/tests/*" = ["C408"]
"astropy/time/*" = ["I001", "C408"]
"astropy/timeseries/*" = ["I001", "C408"]
"astropy/units/*" = ["I001", "C408"]
"astropy/uncertainty/*" = ["C408"]
"astropy/utils/*" = ["C408"]
"astropy/visualization/*" = ["I001", "C408"]
"astropy/wcs/*" = ["I001", "C408"]
"docs/*" = []
"examples/coordinates/*" = []
18 changes: 9 additions & 9 deletions astropy/io/ascii/tests/test_c_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ def test_read_big_table2(tmp_path):
# fast_reader configurations: False| 'use_fast_converter'=False|True
@pytest.mark.parametrize(
"fast_reader",
[False, dict(use_fast_converter=False), dict(use_fast_converter=True)],
[False, {"use_fast_converter": False}, {"use_fast_converter": True}],
)
@pytest.mark.parametrize("parallel", [False, True])
def test_data_out_of_range(parallel, fast_reader, guess):
Expand Down Expand Up @@ -1335,7 +1335,7 @@ def test_data_out_of_range(parallel, fast_reader, guess):
# fast_reader configurations: False| 'use_fast_converter'=False|True
@pytest.mark.parametrize(
"fast_reader",
[False, dict(use_fast_converter=False), dict(use_fast_converter=True)],
[False, {"use_fast_converter": False}, {"use_fast_converter": True}],
)
@pytest.mark.parametrize("parallel", [False, True])
def test_data_at_range_limit(parallel, fast_reader, guess):
Expand Down Expand Up @@ -1648,7 +1648,7 @@ def test_fortran_reader_notbasic():
"""
)[1:-1]

t1 = ascii.read(tabstr.split("\n"), fast_reader=dict(exponent_style="D"))
t1 = ascii.read(tabstr.split("\n"), fast_reader={"exponent_style": "D"})

assert t1["b"].dtype.kind == "f"

Expand All @@ -1663,7 +1663,7 @@ def test_fortran_reader_notbasic():
)[1:-1]

t2 = ascii.read(
tabrdb.split("\n"), format="rdb", fast_reader=dict(exponent_style="fortran")
tabrdb.split("\n"), format="rdb", fast_reader={"exponent_style": "fortran"}
)

assert t2["b"].dtype.kind == "f"
Expand Down Expand Up @@ -1701,7 +1701,7 @@ def test_fortran_reader_notbasic():
tabrst.split("\n"),
format="rst",
guess=False,
fast_reader=dict(use_fast_converter=False),
fast_reader={"use_fast_converter": False},
)

tabrst = tabrst.replace("E", "D")
Expand All @@ -1711,13 +1711,13 @@ def test_fortran_reader_notbasic():
tabrst.split("\n"),
format="rst",
guess=False,
fast_reader=dict(exponent_style="D"),
fast_reader={"exponent_style": "D"},
)


@pytest.mark.parametrize("guess", [True, False])
@pytest.mark.parametrize(
"fast_reader", [dict(exponent_style="D"), dict(exponent_style="A")]
"fast_reader", [{"exponent_style": "D"}, {"exponent_style": "A"}]
)
def test_dict_kwarg_integrity(fast_reader, guess):
"""
Expand All @@ -1732,7 +1732,7 @@ def test_dict_kwarg_integrity(fast_reader, guess):


@pytest.mark.parametrize(
"fast_reader", [False, dict(parallel=True), dict(parallel=False)]
"fast_reader", [False, {"parallel": True}, {"parallel": False}]
)
def test_read_empty_basic_table_with_comments(fast_reader):
"""
Expand All @@ -1751,7 +1751,7 @@ def test_read_empty_basic_table_with_comments(fast_reader):


@pytest.mark.parametrize(
"fast_reader", [dict(use_fast_converter=True), dict(exponent_style="A")]
"fast_reader", [{"use_fast_converter": True}, {"exponent_style": "A"}]
)
def test_conversion_fast(fast_reader):
"""
Expand Down
12 changes: 6 additions & 6 deletions astropy/io/ascii/tests/test_cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ def test_write_byte_by_byte_for_masked_column():
assert lines == exp_output


exp_coord_cols_output = dict(
exp_coord_cols_output = {
# fmt: off
generic=[
"generic": [
'================================================================================',
'Byte-by-byte Description of file: table.dat',
'--------------------------------------------------------------------------------',
Expand All @@ -220,7 +220,7 @@ def test_write_byte_by_byte_for_masked_column():
'HD81809 1e-07 22.25608 2e+00 67 5.0 20 22 02 15.4500000000 -61 39 34.599996000',
'HD103095 -3e+06 27.25000 -9e+34 -30 5.0 20 12 48 15.2244072000 +17 46 26.496624000',
],
positive_de=[
"positive_de": [
'================================================================================',
'Byte-by-byte Description of file: table.dat',
'--------------------------------------------------------------------------------',
Expand All @@ -247,7 +247,7 @@ def test_write_byte_by_byte_for_masked_column():
'HD103095 -3e+06 27.25000 -9e+34 -30 5.0 20 12 48 15.2244072000 +17 46 26.496624000',
],
# fmt: on
galactic=[
"galactic": [
"================================================================================",
"Byte-by-byte Description of file: table.dat",
"--------------------------------------------------------------------------------",
Expand All @@ -268,7 +268,7 @@ def test_write_byte_by_byte_for_masked_column():
"HD81809 1e-07 22.25608 2e+00 67 5.0 20 330.071639591690 -45.548080484609",
"HD103095 -3e+06 27.25000 -9e+34 -30 5.0 20 330.071639591690 -45.548080484609",
],
ecliptic=[
"ecliptic": [
"================================================================================",
"Byte-by-byte Description of file: table.dat",
"--------------------------------------------------------------------------------",
Expand All @@ -289,7 +289,7 @@ def test_write_byte_by_byte_for_masked_column():
"HD81809 1e-07 22.25608 2e+00 67 5.0 20 306.224208650096 -45.621789850825",
"HD103095 -3e+06 27.25000 -9e+34 -30 5.0 20 306.224208650096 -45.621789850825",
],
)
}


def test_write_coord_cols():
Expand Down
8 changes: 4 additions & 4 deletions astropy/io/ascii/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,9 +1563,9 @@ def test_table_with_no_newline():

# Put a single line of column names but with no newline
for kwargs in [
dict(),
dict(guess=False, fast_reader=False, format="basic"),
dict(guess=False, fast_reader=True, format="fast_basic"),
{},
{"guess": False, "fast_reader": False, "format": "basic"},
{"guess": False, "fast_reader": True, "format": "fast_basic"},
]:
table = BytesIO()
table.write(b"a b")
Expand Down Expand Up @@ -1848,7 +1848,7 @@ def test_read_non_ascii():
def test_kwargs_dict_guess(enable):
"""Test that fast_reader dictionary is preserved through guessing sequence."""
# Fails for enable=(True, 'force') - #5578
ascii.read("a\tb\n 1\t2\n3\t 4.0", fast_reader=dict(enable=enable))
ascii.read("a\tb\n 1\t2\n3\t 4.0", fast_reader={"enable": enable})
assert get_read_trace()[-1]["kwargs"]["Reader"] is (
ascii.Tab if (enable is False) else ascii.FastTab
)
Expand Down
Loading

0 comments on commit 7c83005

Please sign in to comment.