Skip to content

Commit

Permalink
Merge pull request astropy#15662 from paverett/fix/ruff_c408_coordinates
Browse files Browse the repository at this point in the history
fix: ruff c408 in coordinates submodule
  • Loading branch information
pllim authored Nov 30, 2023
2 parents cd58714 + 485f54a commit 164a677
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 35 deletions.
1 change: 0 additions & 1 deletion .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ lint.unfixable = [
"astropy/constants/*" = ["N817"] # camelcase-imported-as-acronym
"astropy/convolution/*" = []
"astropy/coordinates/*" = [
"C408", # unnecessary-collection-call
"DTZ007", # call-datetime-strptime-without-zone
]
"astropy/cosmology/*" = [
Expand Down
8 changes: 4 additions & 4 deletions astropy/coordinates/builtin_frames/galactocentric.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class galactocentric_frame_defaults(ScienceState):
_latest_value = "v4.0"
_value = None
_references = None
_state = dict() # all other data
_state = {} # all other data

# Note: _StateProxy() produces read-only view of enclosed mapping.
_registry = {
Expand Down Expand Up @@ -284,11 +284,11 @@ def validate(cls, value):

elif isinstance(value, Galactocentric):
# turn the frame instance into a dict of frame attributes
parameters = dict()
parameters = {}
for k in value.frame_attributes:
parameters[k] = getattr(value, k)
cls._references = value.frame_attribute_references.copy()
cls._state = dict(parameters=parameters, references=cls._references)
cls._state = {"parameters": parameters, "references": cls._references}

else:
raise ValueError(
Expand Down Expand Up @@ -325,7 +325,7 @@ def register(

references = references or {} # None -> {}

state = dict(parameters=parameters, references=references)
state = {"parameters": parameters, "references": references}
state.update(meta) # meta never has keys "parameters" or "references"

cls._registry[name] = state
Expand Down
2 changes: 1 addition & 1 deletion astropy/coordinates/polarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def new_like(self, cols, length, metadata_conflicts="warn", name=None):
shape = (length,) + attrs.pop("shape")
data = np.zeros(shape=shape, dtype=attrs.pop("dtype"))
# Get arguments needed to reconstruct class
out = self._construct_from_dict(dict(value=data))
out = self._construct_from_dict({"value": data})

# Set remaining info attributes
for attr, value in attrs.items():
Expand Down
6 changes: 3 additions & 3 deletions astropy/coordinates/representation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def _validate_differentials(self, differentials):

# Now handle the actual validation of any specified differential classes
if differentials is None:
differentials = dict()
differentials = {}

elif isinstance(differentials, BaseDifferential):
# We can't handle auto-determining the key for this combo
Expand Down Expand Up @@ -807,7 +807,7 @@ def _re_represent_differentials(self, new_rep, differential_class):
attached differentials converted to the new differential classes.
"""
if differential_class is None:
return dict()
return {}

if not self.differentials and differential_class:
raise ValueError("No differentials associated with this representation!")
Expand All @@ -829,7 +829,7 @@ def _re_represent_differentials(self, new_rep, differential_class):
f"representation object ({self.differentials})"
)

new_diffs = dict()
new_diffs = {}
for k in self.differentials:
diff = self.differentials[k]
try:
Expand Down
2 changes: 1 addition & 1 deletion astropy/coordinates/tests/test_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_array_len():
c = ICRS(0 * u.deg, 0 * u.deg)
len(c)

assert c.shape == tuple()
assert c.shape == ()


def test_array_eq():
Expand Down
2 changes: 1 addition & 1 deletion astropy/coordinates/tests/test_erfa_astrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_interpolation_nd():
interp_provider = ErfaAstromInterpolator(300 * u.s)
provider = ErfaAstrom()

for shape in [tuple(), (1,), (10,), (3, 2), (2, 10, 5), (4, 5, 3, 2)]:
for shape in [(), (1,), (10,), (3, 2), (2, 10, 5), (4, 5, 3, 2)]:
# create obstimes of the desired shapes
delta_t = np.linspace(0, 12, np.prod(shape, dtype=int)) * u.hour
obstime = (Time("2020-01-01T18:00") + delta_t).reshape(shape)
Expand Down
2 changes: 1 addition & 1 deletion astropy/coordinates/tests/test_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ def test_galactocentric_defaults():
with galactocentric_frame_defaults.set("latest"):
params = galactocentric_frame_defaults.validate(galcen_latest)
references = galcen_latest.frame_attribute_references
state = dict(parameters=params, references=references)
state = {"parameters": params, "references": references}

assert galactocentric_frame_defaults.parameters == params
assert galactocentric_frame_defaults.references == references
Expand Down
4 changes: 2 additions & 2 deletions astropy/coordinates/tests/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_constellations(recwarn):

assert res == "Ursa Major"
assert res_short == "UMa"
assert isinstance(res, str) or getattr(res, "shape", None) == tuple()
assert isinstance(res, str) or getattr(res, "shape", None) == ()

# these are taken from the ReadMe for Roman 1987
ras = [9, 23.5, 5.12, 9.4555, 12.8888, 15.6687, 19, 6.2222]
Expand All @@ -84,7 +84,7 @@ def test_constellations(recwarn):
# non-ASCII character
boores = get_constellation(SkyCoord(15 * u.hour, 30 * u.deg, frame="icrs"))
assert boores == "Boötes"
assert isinstance(boores, str) or getattr(boores, "shape", None) == tuple()
assert isinstance(boores, str) or getattr(boores, "shape", None) == ()


@pytest.mark.xfail
Expand Down
4 changes: 2 additions & 2 deletions astropy/coordinates/tests/test_name_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from astropy.coordinates.sky_coordinate import SkyCoord

_cached_ngc3642 = dict()
_cached_ngc3642 = {}
_cached_ngc3642[
"simbad"
] = """# NGC 3642 #Q22523669
Expand Down Expand Up @@ -75,7 +75,7 @@
#====Done (2013-Feb-12,16:39:48z)===="""

_cached_castor = dict()
_cached_castor = {}
_cached_castor[
"all"
] = """# castor #Q22524249
Expand Down
10 changes: 5 additions & 5 deletions astropy/coordinates/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ def test_regression_3920():

aa = AltAz(location=loc, obstime=time)
sc = SkyCoord(10 * u.deg, 3 * u.deg)
assert sc.transform_to(aa).shape == tuple()
assert sc.transform_to(aa).shape == ()
# That part makes sense: the input is a scalar so the output is too

sc2 = SkyCoord(10 * u.deg, 3 * u.deg, 1 * u.AU)
assert sc2.transform_to(aa).shape == tuple()
assert sc2.transform_to(aa).shape == ()
# in 3920 that assert fails, because the shape is (1,)

# check that the same behavior occurs even if transform is from low-level classes
icoo = ICRS(sc.data)
icoo2 = ICRS(sc2.data)
assert icoo.transform_to(aa).shape == tuple()
assert icoo2.transform_to(aa).shape == tuple()
assert icoo.transform_to(aa).shape == ()
assert icoo2.transform_to(aa).shape == ()


def test_regression_3938():
Expand Down Expand Up @@ -443,7 +443,7 @@ def test_regression_5743():
sc = SkyCoord(
[5, 10], [20, 30], unit=u.deg, obstime=["2017-01-01T00:00", "2017-01-01T00:10"]
)
assert sc[0].obstime.shape == tuple()
assert sc[0].obstime.shape == ()


def test_regression_5889_5890():
Expand Down
2 changes: 1 addition & 1 deletion astropy/coordinates/tests/test_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_transform(self):

# let's also check with differentials
dif = RadialDifferential(d_distance=-3 * u.km / u.s)
rep = rep.with_differentials(dict(s=dif))
rep = rep.with_differentials({"s": dif})

newrep = rep.transform(matrix)
assert newrep.distance == 30 * u.kpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_mul_div(self, representation):
with pytest.raises(TypeError):
in_rep * in_rep
with pytest.raises(TypeError):
dict() * in_rep
{} * in_rep

def test_mul_div_unit_spherical(self):
s1 = self.unit_spherical * self.distance
Expand Down
16 changes: 8 additions & 8 deletions astropy/coordinates/tests/test_sky_coord_velocities.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def sc(request):
incldist, inclrv = request.param

args = [1 * u.deg, 2 * u.deg]
kwargs = dict(pm_dec=1 * u.mas / u.yr, pm_ra_cosdec=2 * u.mas / u.yr)
kwargs = {"pm_dec": 1 * u.mas / u.yr, "pm_ra_cosdec": 2 * u.mas / u.yr}
if incldist:
kwargs["distance"] = 213.4 * u.pc
if inclrv:
Expand Down Expand Up @@ -291,17 +291,17 @@ def test_cartesian_to_spherical(sph_type):
@pytest.mark.parametrize(
"diff_info, diff_cls",
[
(dict(radial_velocity=[20, 30] * u.km / u.s), RadialDifferential),
({"radial_velocity": [20, 30] * u.km / u.s}, RadialDifferential),
(
dict(
pm_ra=[2, 3] * u.mas / u.yr,
pm_dec=[-3, -4] * u.mas / u.yr,
differential_type="unitspherical",
),
{
"pm_ra": [2, 3] * u.mas / u.yr,
"pm_dec": [-3, -4] * u.mas / u.yr,
"differential_type": "unitspherical",
},
UnitSphericalDifferential,
),
(
dict(pm_ra_cosdec=[2, 3] * u.mas / u.yr, pm_dec=[-3, -4] * u.mas / u.yr),
{"pm_ra_cosdec": [2, 3] * u.mas / u.yr, "pm_dec": [-3, -4] * u.mas / u.yr},
UnitSphericalCosLatDifferential,
),
],
Expand Down
8 changes: 4 additions & 4 deletions astropy/coordinates/tests/test_spectral_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,10 @@ def test_shift_to_rest_star_withobserver():
@pytest.mark.parametrize(
"sc_kwargs",
[
dict(radial_velocity=0 * u.km / u.s),
dict(observer=gcrs_origin, radial_velocity=0 * u.km / u.s),
dict(target=gcrs_origin, radial_velocity=0 * u.km / u.s),
dict(observer=gcrs_origin, target=gcrs_not_origin),
{"radial_velocity": 0 * u.km / u.s},
{"observer": gcrs_origin, "radial_velocity": 0 * u.km / u.s},
{"target": gcrs_origin, "radial_velocity": 0 * u.km / u.s},
{"observer": gcrs_origin, "target": gcrs_not_origin},
],
)
def test_los_shift(sc_kwargs):
Expand Down

0 comments on commit 164a677

Please sign in to comment.