Skip to content

Commit

Permalink
More conservative warning suppression
Browse files Browse the repository at this point in the history
  • Loading branch information
aarchiba committed Feb 18, 2024
1 parent 2acf220 commit e0f0e69
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ the released changes.
- Moved `get_derived_params` to `timing_model`
- `check_ephemeris_connection` CI test no longer requires access to static NANOGrav site
- `TimingModel.compare()` now calls `change_binary_epoch()`.
- Turned ErfaWarning into an exception during testing; cleaned up test suite.
### Added
- Added numdifftools to setup.cfg to match requirements.txt
- Documentation: Added `convert_parfile` to list of command-line tools in RTD
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
error::erfa.ErfaWarning
26 changes: 16 additions & 10 deletions src/pint/observatory/clock_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,16 +523,22 @@ def add_comment(s):
mjd = mjd[1:]
clk = clk[1:]
comments = comments[1:]
return ClockFile(
mjd,
clk * u.s,
filename=filename,
comments=comments,
leading_comment=leading_comment,
header=header,
friendly_name=friendly_name,
valid_beyond_ends=valid_beyond_ends,
)
with warnings.catch_warnings():
# Some clock files have dubious years in them
# Most are removed by automatically ignoring MJD 0, or with "bogus_last_correction"
# But Parkes incudes a non-zero correction for MJD 0 so it isn't removed
# In any case, the user doesn't need a warning about strange years in clock files
warnings.filterwarnings("ignore", r".*dubious year", erfa.ErfaWarning)
return ClockFile(
mjd,
clk * u.s,
filename=filename,
comments=comments,
leading_comment=leading_comment,
header=header,
friendly_name=friendly_name,
valid_beyond_ends=valid_beyond_ends,
)


ClockFile._formats["tempo2"] = read_tempo2_clock_file
Expand Down
14 changes: 3 additions & 11 deletions src/pint/pulsar_mjd.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,7 @@ def time_from_longdouble(t, scale="utc", format="pulsar_mjd"):
t = np.longdouble(t)
i = float(np.floor(t))
f = float(t - i)
# FIXME: double-check whether warnings from here could be useful
# if they only arise because of weird test inputs silence them in the tests
with warnings.catch_warnings():
warnings.filterwarnings("ignore", r".*dubious year", erfa.ErfaWarning)
return astropy.time.Time(val=i, val2=f, format=format, scale=scale)
return astropy.time.Time(val=i, val2=f, format=format, scale=scale)


def time_to_mjd_string(t):
Expand Down Expand Up @@ -405,9 +401,7 @@ def jds_to_mjds_pulsar(jd1, jd2):
# Note this will return an incorrect value during
# leap seconds, so raise an exception in that
# case.
with warnings.catch_warnings():
warnings.filterwarnings("ignore", r".*dubious year", erfa.ErfaWarning)
y, mo, d, hmsf = erfa.d2dtf("UTC", _digits, jd1, jd2)
y, mo, d, hmsf = erfa.d2dtf("UTC", _digits, jd1, jd2)
# For ASTROPY_LT_3_1, convert to the new structured array dtype that
# is returned by the new erfa gufuncs.
if not hmsf.dtype.names:
Expand Down Expand Up @@ -450,9 +444,7 @@ def mjds_to_jds_pulsar(mjd1, mjd2):
f -= m
f *= 60
s = f
with warnings.catch_warnings():
warnings.filterwarnings("ignore", r".*dubious year", erfa.ErfaWarning)
return erfa.dtf2d("UTC", y, mo, d, h, m, s)
return erfa.dtf2d("UTC", y, mo, d, h, m, s)


# Please forgive the horrible hacks to make these work cleanly on both arrays
Expand Down
3 changes: 0 additions & 3 deletions tests/pytest.ini

This file was deleted.

0 comments on commit e0f0e69

Please sign in to comment.