Skip to content

Commit

Permalink
Ruff root files (#2849)
Browse files Browse the repository at this point in the history
* ruff on top level files

* ruff unsafe on cmfgen2tardis
  • Loading branch information
atharva-2001 authored Oct 21, 2024
1 parent 14841c9 commit 6ae9446
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion tardis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
" after TARDIS."
)
else:
from astropy import physical_constants, astronomical_constants
from astropy import astronomical_constants, physical_constants

physical_constants.set("codata2014")
astronomical_constants.set("iau2012")
Expand Down
1 change: 1 addition & 0 deletions tardis/_astropy_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@

# Create the test function for self test
from astropy.tests.runner import TestRunner

test = TestRunner.make_test_runner_in(os.path.dirname(__file__))
5 changes: 2 additions & 3 deletions tardis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import logging


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -70,9 +69,9 @@ def run_tardis(
-----
Please see the `logging tutorial <https://tardis-sn.github.io/tardis/io/optional/logging_configuration.html>`_ to know more about `log_level` and `specific` options.
"""
from tardis.io.logger.logger import logging_state
from tardis.io.configuration.config_reader import Configuration
from tardis.io.atom_data.base import AtomData
from tardis.io.configuration.config_reader import Configuration
from tardis.io.logger.logger import logging_state
from tardis.simulation import Simulation

if isinstance(config, Configuration):
Expand Down
10 changes: 4 additions & 6 deletions tardis/scripts/cmfgen2tardis.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import os
import sys
import argparse
import os

import numpy as np
import pandas as pd

from tardis.io.atom_data import AtomData

# The from_hdf() method requires an argument, so the line below doesn't work
# atomic_dataset = AtomData.from_hdf()

Expand Down Expand Up @@ -40,7 +38,7 @@ def extract_file_block(f):
def convert_format(file_path):
quantities_row = []
prop_list = ["Velocity", "Density", "Electron density", "Temperature"]
with open(file_path, "r") as f:
with open(file_path) as f:
for line in f:
items = line.replace("(", "").replace(")", "").split()
n = len(items)
Expand Down Expand Up @@ -102,7 +100,7 @@ def parse_file(args):
)

filename = os.path.splitext(os.path.basename(args.input_path))[0]
save_fname = ".".join((filename, "csv"))
save_fname = f"{filename}.csv"
resultant_df = pd.concat([density_df, abundances_df], axis=1)
resultant_df.columns = pd.MultiIndex.from_tuples(
zip(resultant_df.columns, quantities_row)
Expand Down
2 changes: 1 addition & 1 deletion tardis/tests/fixtures/atom_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from copy import deepcopy
from pathlib import Path

import pytest

from tardis.io.atom_data.base import AtomData
Expand Down
7 changes: 4 additions & 3 deletions tardis/tests/integration_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import glob
import os
import yaml

import pandas as pd
import pytest
import yaml

# NOTE: the __githash__ variable is not available anymore
# on `version.py`. Find another way to fix it!
Expand Down Expand Up @@ -87,8 +88,8 @@ def reference(request, data_path):
else:
try:
reference = pd.HDFStore(data_path["reference_path"], "r")
except IOError:
raise IOError(
except OSError:
raise OSError(
f'Reference file {data_path["reference_path"]} does not exist and is needed'
f" for the tests"
)
Expand Down
8 changes: 4 additions & 4 deletions tardis/tests/integration_tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import os

import yaml
import pytest
import matplotlib
import pytest
import yaml

matplotlib.use("Agg")
import matplotlib.pyplot as plt
from numpy.testing import assert_allclose

from tardis.io.atom_data.base import AtomData
from tardis.simulation import Simulation
from tardis.io.configuration.config_reader import Configuration
from tardis.simulation import Simulation

pytestmarker = [pytest.mark.no_cover, pytest.mark.integration]

Expand Down Expand Up @@ -71,7 +71,7 @@ def model_quantities(request):
reason="integration tests are not included in this run",
)
@pytest.mark.integration
class TestIntegration(object):
class TestIntegration:
"""Slow integration test for various setups present in subdirectories of
``tardis/tests/integration_tests``.
"""
Expand Down
26 changes: 12 additions & 14 deletions tardis/tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import pytest
import numpy as np
import numpy.testing as npt
from io import StringIO

import numpy as np
import pytest
from astropy import units as u
from io import StringIO

from tardis.util.base import (
MalformedSpeciesError,
MalformedElementSymbolError,
MalformedQuantityError,
int_to_roman,
roman_to_int,
MalformedSpeciesError,
atomic_number2element_symbol,
calculate_luminosity,
create_synpp_yaml,
convert_abundances_format,
element_symbol2atomic_number,
int_to_roman,
intensity_black_body,
species_tuple_to_string,
species_string_to_tuple,
parse_quantity,
element_symbol2atomic_number,
atomic_number2element_symbol,
reformat_element_symbol,
quantity_linspace,
convert_abundances_format,
reformat_element_symbol,
roman_to_int,
species_string_to_tuple,
species_tuple_to_string,
)


Expand Down

0 comments on commit 6ae9446

Please sign in to comment.