Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,11 @@ Other Changes and Additions
that require only data from data.astropy.org, and ``--remote-data=any`` is
the same as ``--remote-data`` (run all tests that use remote data). [#5506]

- The pytest ``recwarn`` fixture has been removed from the tests in favor of
``utils.catch_warnings``. [#5489]

- Deprecated escape sequences in strings (Python 3.6) have been removed. [#5489]

1.2.2 (unreleased)
------------------

Expand Down
14 changes: 7 additions & 7 deletions astropy/_erfa/erfa_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,15 @@ def __init__(self, name, source_path, match_line=None):
else:
filecontents = f.read()

pattern = "\n([^\n]+{0} ?\([^)]+\)).+?(/\*.+?\*/)".format(name)
pattern = r"\n([^\n]+{0} ?\([^)]+\)).+?(/\*.+?\*/)".format(name)
p = re.compile(pattern, flags=re.DOTALL|re.MULTILINE)

search = p.search(filecontents)
self.cfunc = " ".join(search.group(1).split())
self.doc = FunctionDoc(search.group(2))

self.args = []
for arg in re.search("\(([^)]+)\)", self.cfunc).group(1).split(', '):
for arg in re.search(r"\(([^)]+)\)", self.cfunc).group(1).split(', '):
self.args.append(Argument(arg, self.doc))
self.ret = re.search("^(.*){0}".format(name), self.cfunc).group(1).strip()
if self.ret != 'void':
Expand Down Expand Up @@ -391,14 +391,14 @@ def surround(a_list, pre, post):
erfa_h = f.read()

funcs = OrderedDict()
section_subsection_functions = re.findall('/\* (\w*)/(\w*) \*/\n(.*?)\n\n',
section_subsection_functions = re.findall(r'/\* (\w*)/(\w*) \*/\n(.*?)\n\n',
erfa_h, flags=re.DOTALL|re.MULTILINE)
for section, subsection, functions in section_subsection_functions:
print_("{0}.{1}".format(section, subsection))
if ((section == "Astronomy") or (subsection == "AngleOps")
or (subsection == "SphericalCartesian")
or (subsection == "MatrixVectorProducts")):
func_names = re.findall(' (\w+)\(.*?\);', functions, flags=re.DOTALL)
func_names = re.findall(r' (\w+)\(.*?\);', functions, flags=re.DOTALL)
for name in func_names:
print_("{0}.{1}.{2}...".format(section, subsection, name))
if multifilserc:
Expand All @@ -409,7 +409,7 @@ def surround(a_list, pre, post):
# the start of the header declaration, otherwise it
# might find a *call* of the function instead of the
# definition
for line in functions.split('\n'):
for line in functions.split(r'\n'):
if name in line:
# [:-1] is to remove trailing semicolon, and
# splitting on '(' is because the header and
Expand All @@ -433,9 +433,9 @@ def surround(a_list, pre, post):
erfa_m_h = f.read()
constants = []
for chunk in erfa_m_h.split("\n\n"):
result = re.findall("#define (ERFA_\w+?) (.+?)$", chunk, flags=re.DOTALL|re.MULTILINE)
result = re.findall(r"#define (ERFA_\w+?) (.+?)$", chunk, flags=re.DOTALL|re.MULTILINE)
if result:
doc = re.findall("/\* (.+?) \*/\n", chunk, flags=re.DOTALL)
doc = re.findall(r"/\* (.+?) \*/\n", chunk, flags=re.DOTALL)
for (name, value) in result:
constants.append(Constant(name, value, doc))

Expand Down
19 changes: 12 additions & 7 deletions astropy/_erfa/tests/test_erfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np
from .. import core as erfa
from ...tests.helper import catch_warnings


def test_erfa_wrapper():
Expand Down Expand Up @@ -93,7 +94,7 @@ def test_spherical_cartesian():
np.testing.assert_allclose(pv, [[0.0,np.sqrt(2.0),np.sqrt(2.0)],[-1.0,0.0,0.0]], atol=1e-14)


def test_errwarn_reporting(recwarn):
def test_errwarn_reporting():
"""
Test that the ERFA error reporting mechanism works as it should
"""
Expand All @@ -102,14 +103,18 @@ def test_errwarn_reporting(recwarn):
erfa.dat(1990, 1, 1, 0.5)

# check warning is raised for a scalar
erfa.dat(100, 1, 1, 0.5)
w = recwarn.pop(erfa.ErfaWarning)
assert '1 of "dubious year (Note 1)"' in str(w.message)
with catch_warnings() as w:
erfa.dat(100, 1, 1, 0.5)
assert len(w) == 1
assert w[0].category == erfa.ErfaWarning
assert '1 of "dubious year (Note 1)"' in str(w[0].message)

# and that the count is right for a vector.
erfa.dat([100, 200, 1990], 1, 1, 0.5)
w = recwarn.pop(erfa.ErfaWarning)
assert '2 of "dubious year (Note 1)"' in str(w.message)
with catch_warnings() as w:
erfa.dat([100, 200, 1990], 1, 1, 0.5)
assert len(w) == 1
assert w[0].category == erfa.ErfaWarning
assert '2 of "dubious year (Note 1)"' in str(w[0].message)

try:
erfa.dat(1990, [1, 34, 2], [1, 1, 43], 0.5)
Expand Down
2 changes: 1 addition & 1 deletion astropy/coordinates/sky_coordinate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,7 @@ def from_pixel(cls, xp, yp, wcs, origin=0, mode='all'):
# Table interactions
@classmethod
def guess_from_table(cls, table, **coord_kwargs):
"""
r"""
A convenience method to create and return a new `SkyCoord` from the data
in an astropy Table.

Expand Down
2 changes: 1 addition & 1 deletion astropy/coordinates/tests/test_angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ def test_repr_latex():
arrangle = Angle([1, 2.1], u.deg)
rlarrangle = arrangle._repr_latex_()

assert rlscangle == '$2^\circ06{}^\prime00{}^{\prime\prime}$'
assert rlscangle == r'$2^\circ06{}^\prime00{}^{\prime\prime}$'
assert rlscangle.split('$')[1] in rlarrangle

# make sure the ... appears for large arrays
Expand Down
14 changes: 8 additions & 6 deletions astropy/coordinates/tests/test_iau_fullstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..builtin_frames.utils import get_jd12
from .. import EarthLocation
from .. import SkyCoord
from ...tests.helper import pytest
from ...tests.helper import pytest, catch_warnings
from ... import _erfa as erfa
from ...utils import iers
from .utils import randomly_sample_sphere
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_fiducial_roudtrip(fullstack_icrs, fullstack_fiducial_altaz):
npt.assert_allclose(fullstack_icrs.dec.deg, icrs2.dec.deg)


def test_future_altaz(recwarn):
def test_future_altaz():
"""
While this does test the full stack, it is mostly meant to check that a
warning is raised when attempting to get to AltAz in the future (beyond
Expand All @@ -152,10 +152,12 @@ def test_future_altaz(recwarn):
if hasattr(utils, '__warningregistry__'):
utils.__warningregistry__.clear()

location = EarthLocation(lat=0*u.deg, lon=0*u.deg)
t = Time('J2161')
with catch_warnings() as found_warnings:

SkyCoord(1*u.deg, 2*u.deg).transform_to(AltAz(location=location, obstime=t))
location = EarthLocation(lat=0*u.deg, lon=0*u.deg)
t = Time('J2161')

SkyCoord(1*u.deg, 2*u.deg).transform_to(AltAz(location=location, obstime=t))

# check that these message(s) appear among any other warnings. If tests are run with
# --remote-data then the IERS table will be an instance of IERS_Auto which is
Expand All @@ -167,7 +169,7 @@ def test_future_altaz(recwarn):
messages_to_find.append("(some) times are outside of range covered by IERS table.")

messages_found = [False for _ in messages_to_find]
for w in recwarn.list:
for w in found_warnings:
if issubclass(w.category, AstropyWarning):
for i, message_to_find in enumerate(messages_to_find):
if message_to_find in str(w.message):
Expand Down
14 changes: 7 additions & 7 deletions astropy/coordinates/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from ...time import Time
from ...utils import iers

from ...tests.helper import pytest, assert_quantity_allclose
from ...tests.helper import pytest, assert_quantity_allclose, catch_warnings
from .test_matching import HAS_SCIPY, OLDER_SCIPY


Expand Down Expand Up @@ -182,7 +182,7 @@ def test_regression_4210():
eclobj.distance


def test_regression_futuretimes_4302(recwarn):
def test_regression_futuretimes_4302():
"""
Checks that an error is not raised for future times not covered by IERS
tables (at least in a simple transform like CIRS->ITRS that simply requires
Expand All @@ -198,14 +198,14 @@ def test_regression_futuretimes_4302(recwarn):
if hasattr(utils, '__warningregistry__'):
utils.__warningregistry__.clear()

future_time = Time('2511-5-1')

c = CIRS(1*u.deg, 2*u.deg, obstime=future_time)
c.transform_to(ITRS(obstime=future_time))
with catch_warnings() as found_warnings:
future_time = Time('2511-5-1')
c = CIRS(1*u.deg, 2*u.deg, obstime=future_time)
c.transform_to(ITRS(obstime=future_time))

if not isinstance(iers.IERS_Auto.iers_table, iers.IERS_Auto):
saw_iers_warnings = False
for w in recwarn.list:
for w in found_warnings:
if issubclass(w.category, AstropyWarning):
if '(some) times are outside of range covered by IERS table' in str(w.message):
saw_iers_warnings = True
Expand Down
28 changes: 14 additions & 14 deletions astropy/cosmology/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ def _w_integrand(self, ln1pz):
return 1.0 + self.w(z)

def de_density_scale(self, z):
""" Evaluates the redshift dependence of the dark energy density.
r""" Evaluates the redshift dependence of the dark energy density.

Parameters
----------
Expand All @@ -815,13 +815,13 @@ def de_density_scale(self, z):

Notes
-----
The scaling factor, I, is defined by :math:`\\rho(z) = \\rho_0 I`,
The scaling factor, I, is defined by :math:`\rho(z) = \rho_0 I`,
and is given by

.. math::

I = \\exp \\left( 3 \int_{a}^1 \\frac{ da^{\\prime} }{ a^{\\prime} }
\\left[ 1 + w\\left( a^{\\prime} \\right) \\right] \\right)
I = \exp \left( 3 \int_{a}^1 \frac{ da^{\prime} }{ a^{\prime} }
\left[ 1 + w\left( a^{\prime} \right) \right] \right)

It will generally helpful for subclasses to overload this method if
the integral can be done analytically for the particular dark
Expand Down Expand Up @@ -2367,7 +2367,7 @@ def w(self, z):
return self._w0 + self._wa * z / (1.0 + z)

def de_density_scale(self, z):
""" Evaluates the redshift dependence of the dark energy density.
r""" Evaluates the redshift dependence of the dark energy density.

Parameters
----------
Expand All @@ -2386,8 +2386,8 @@ def de_density_scale(self, z):

.. math::

I = \\left(1 + z\\right)^{3 \\left(1 + w_0 + w_a\\right)}
\exp \\left(-3 w_a \\frac{z}{1+z}\\right)
I = \left(1 + z\right)^{3 \left(1 + w_0 + w_a\right)}
\exp \left(-3 w_a \frac{z}{1+z}\right)

"""
if isiterable(z):
Expand Down Expand Up @@ -2651,7 +2651,7 @@ def w(self, z):
return self._wp + self._wa * (apiv - 1.0 / (1. + z))

def de_density_scale(self, z):
""" Evaluates the redshift dependence of the dark energy density.
r""" Evaluates the redshift dependence of the dark energy density.

Parameters
----------
Expand All @@ -2670,10 +2670,10 @@ def de_density_scale(self, z):

.. math::

a_p = \\frac{1}{1 + z_p}
a_p = \frac{1}{1 + z_p}

I = \\left(1 + z\\right)^{3 \\left(1 + w_p + a_p w_a\\right)}
\exp \\left(-3 w_a \\frac{z}{1+z}\\right)
I = \left(1 + z\right)^{3 \left(1 + w_p + a_p w_a\right)}
\exp \left(-3 w_a \frac{z}{1+z}\right)
"""

if isiterable(z):
Expand Down Expand Up @@ -2825,7 +2825,7 @@ def w(self, z):
return self._w0 + self._wz * z

def de_density_scale(self, z):
""" Evaluates the redshift dependence of the dark energy density.
r""" Evaluates the redshift dependence of the dark energy density.

Parameters
----------
Expand All @@ -2844,8 +2844,8 @@ def de_density_scale(self, z):

.. math::

I = \\left(1 + z\\right)^{3 \\left(1 + w_0 - w_z\\right)}
\exp \\left(-3 w_z z\\right)
I = \left(1 + z\right)^{3 \left(1 + w_0 - w_z\right)}
\exp \left(-3 w_z z\right)
"""

if isiterable(z):
Expand Down
2 changes: 1 addition & 1 deletion astropy/io/ascii/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BasicData(core.BaseData):


class Basic(core.BaseReader):
"""
r"""
Read a character-delimited table with a single header line at the top
followed by data lines to the end of the table. Lines beginning with # as
the first non-whitespace character are comments. This reader is highly
Expand Down
4 changes: 2 additions & 2 deletions astropy/io/ascii/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def process_line(self, line):
"""Remove whitespace at the beginning or end of line. This is especially useful for
whitespace-delimited files to prevent spurious columns at the beginning or end.
If splitting on whitespace then replace unquoted tabs with space first"""
if self.delimiter == '\s':
if self.delimiter == r'\s':
line = _replace_tab_with_space(line, self.escapechar, self.quotechar)
return line.strip()

Expand Down Expand Up @@ -420,7 +420,7 @@ def __call__(self, lines):
quotechar = None if self.quotechar is None else str(self.quotechar)
delimiter = None if self.delimiter is None else str(self.delimiter)

if delimiter == '\s':
if delimiter == r'\s':
delimiter = ' '

csv_reader = csv.reader(lines,
Expand Down
2 changes: 1 addition & 1 deletion astropy/io/ascii/daophot.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class DaophotHeader(core.BaseHeader):
comment = r'\s*#K'

# Regex for extracting the format strings
re_format = re.compile('%-?(\d+)\.?\d?[sdfg]')
re_format = re.compile(r'%-?(\d+)\.?\d?[sdfg]')
re_header_keyword = re.compile(r'[#]K'
r'\s+ (?P<name> \w+)'
r'\s* = (?P<stuff> .+) $',
Expand Down
4 changes: 2 additions & 2 deletions astropy/io/ascii/ipac.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def str_vals(self):
'This causes duplicate column names: {0}'.format(doublenames))

for name in namelist:
m = re.match('\w+', name)
m = re.match(r'\w+', name)
if m.end() != len(name):
raise IpacFormatE('{0} - Only alphanumeric characters and _ '
'are allowed in column names.'.format(name))
Expand Down Expand Up @@ -324,7 +324,7 @@ def write(self, lines, widths, vals_list):


class Ipac(basic.Basic):
"""Read or write an IPAC format table. See
r"""Read or write an IPAC format table. See
http://irsa.ipac.caltech.edu/applications/DDGEN/Doc/ipac_tbl.html::

\\name=value
Expand Down
6 changes: 3 additions & 3 deletions astropy/io/ascii/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def write(self, table=None):


class AASTexHeaderSplitter(LatexSplitter):
'''Extract column names from a `deluxetable`_.
r'''Extract column names from a `deluxetable`_.

This splitter expects the following LaTeX code **in a single line**:

Expand All @@ -352,7 +352,7 @@ def join(self, vals):


class AASTexHeader(LatexHeader):
'''In a `deluxetable
r'''In a `deluxetable
<http://fits.gsfc.nasa.gov/standard30/deluxetable.sty>`_ some header
keywords differ from standard LaTeX.

Expand Down Expand Up @@ -387,7 +387,7 @@ def write(self, lines):


class AASTexData(LatexData):
'''In a `deluxetable`_ the data is enclosed in `\startdata` and `\enddata`
r'''In a `deluxetable`_ the data is enclosed in `\startdata` and `\enddata`
'''
data_start = r'\startdata'
data_end = r'\enddata'
Expand Down
2 changes: 1 addition & 1 deletion astropy/io/ascii/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def get_testfiles(name=None):
{'name': 't/whitespace.dat',
'cols': ('quoted colname with tab\tinside', 'col2', 'col3'),
'nrows': 2,
'opts': {'delimiter': '\s'}},
'opts': {'delimiter': r'\s'}},
{'name': 't/simple_csv.csv',
'cols': ('a','b','c'),
'nrows': 2,
Expand Down
4 changes: 2 additions & 2 deletions astropy/io/ascii/tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ def test_latex_units():
out = StringIO()
ascii.write(t, out, format='aastex', latexdict=ascii.latexdicts['AA'])
assert out.getvalue() == expected.replace(
'colhead{s}', 'colhead{$\mathrm{s}$}').replace(
'colhead{ }', 'colhead{$\mathrm{yr}$}')
'colhead{s}', r'colhead{$\mathrm{s}$}').replace(
'colhead{ }', r'colhead{$\mathrm{yr}$}')


@pytest.mark.parametrize("fast_writer", [True, False])
Expand Down
Loading