From 84cf2e63fb9d9ccddca5dd3efdd4c29998508bc2 Mon Sep 17 00:00:00 2001 From: Alexander Holas <70367168+AlexHls@users.noreply.github.com> Date: Wed, 15 Nov 2023 17:10:19 +0100 Subject: [PATCH] Add astropy import guard (#2470) * Add astropy import guard * mailmap --- .mailmap | 1 + tardis/__init__.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.mailmap b/.mailmap index e8de40e3ee3..0525b2ec384 100644 --- a/.mailmap +++ b/.mailmap @@ -5,6 +5,7 @@ Alexander Holas Alexander Holas Alexander Holas AlexHls <70367168+AlexHls@users.noreply.github.com> Alexander Holas AlexHls +Alexander Holas <70367168+AlexHls@users.noreply.github.com> Alice Harpole Alice Harpole Alice Harpole diff --git a/tardis/__init__.py b/tardis/__init__.py index 14980a8dfed..5d2ec94e90b 100644 --- a/tardis/__init__.py +++ b/tardis/__init__.py @@ -12,13 +12,20 @@ # ---------------------------------------------------------------------------- import sys +import warnings # ---------------------------------------------------------------------------- -from astropy import physical_constants, astronomical_constants +if ("astropy.units" in sys.modules) or ("astropy.constants" in sys.modules): + warnings.warn( + "Astropy is already imported externally. Astropy should be imported" + " after TARDIS." + ) +else: + from astropy import physical_constants, astronomical_constants -physical_constants.set("codata2014") -astronomical_constants.set("iau2012") + physical_constants.set("codata2014") + astronomical_constants.set("iau2012") # ----------------------------------------------------------------------------