Skip to content

Commit

Permalink
Allow dimensionless phase input.
Browse files Browse the repository at this point in the history
  • Loading branch information
mhvk committed May 9, 2020
1 parent 5b330ba commit 18e0c49
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/pint/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from astropy.time.utils import two_sum, two_product
from astropy.utils import minversion

from pint import dimensionless_cycles


__all__ = ['Phase', 'FractionalPhase']

Expand Down Expand Up @@ -168,8 +170,10 @@ def __new__(cls, angle, unit=None, wrap_angle=None, **kwargs):
# maybe via astype.
if isinstance(angle, Phase):
angle = angle['frac']
return super().__new__(cls, angle, unit=unit, wrap_angle=wrap_angle,
**kwargs)

with u.add_enabled_equivalencies(dimensionless_cycles):
return super().__new__(cls, angle, unit=unit, wrap_angle=wrap_angle,
**kwargs)


def check_imaginary(a):
Expand Down Expand Up @@ -253,7 +257,8 @@ def __new__(cls, phase1, phase2=None, copy=True, subok=False):
phase1 = phase1.view(cls)
return phase1.copy() if copy else phase1

phase1 = Angle(phase1, cls._unit, copy=False)
with u.add_enabled_equivalencies(dimensionless_cycles):
phase1 = Angle(phase1, cls._unit, copy=False)

if phase2 is not None:
if isinstance(phase2, Phase):
Expand All @@ -262,7 +267,8 @@ def __new__(cls, phase1, phase2=None, copy=True, subok=False):
phase2 = phase2.view(cls)
return phase2

phase2 = Angle(phase2, cls._unit, copy=False)
with u.add_enabled_equivalencies(dimensionless_cycles):
phase2 = Angle(phase2, cls._unit, copy=False)

return cls.from_angles(phase1, phase2)

Expand Down

0 comments on commit 18e0c49

Please sign in to comment.