Skip to content

Commit

Permalink
Update daf_base to numpydoc standard
Browse files Browse the repository at this point in the history
  • Loading branch information
squisty committed Jun 25, 2020
1 parent 66397f0 commit 2fe3899
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 21 deletions.
10 changes: 9 additions & 1 deletion python/lsst/daf/base/dateTime/dateTimeContinued.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ class DateTime:
def toPython(self, timescale=None):
"""Convert a DateTime to Python's datetime
@param timescale Timescale for resultant datetime
Parameters
----------
timescale : `dateTime.DateTime.Timescale`, optional
Timescale for resultant datetime.
Returns
-------
datetime : `datetime.datetime`
A converted python datetime object.
"""
import datetime
nsecs = self.nsecs(timescale) if timescale is not None else self.nsecs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ class ReturnStyle(enum.Enum):


def _propertyContainerElementTypeName(container, name):
"""Return name of the type of a particular element"""
"""Return name of the type of a particular element
Parameters
----------
container : `lsst.daf.base.PropertySet` or `lsst.daf.base.PropertyList`
Container from which to get the value
name : `str`
Name of item
"""
try:
t = container.typeOf(name)
except LookupError as e:
Expand Down Expand Up @@ -223,7 +231,22 @@ def _guessIntegerType(container, name, value):
If there is no pre-existing value we have to decide what to do. For now
we pick Int if the value is less than maxsize.
Returns None if the value supplied is a bool or not an integral value.
Parameters
----------
container : `lsst.daf.base.PropertySet` or `lsst.daf.base.PropertyList`
Container from which to get the value
name : `str`
Name of item
value : `object`
Value to be assigned a type
Returns
-------
useType : `str` or none
Use type for the given input. Returns none if input
is bool or a non integral value.
"""
useType = None
maxInt = 2147483647
Expand Down Expand Up @@ -266,7 +289,8 @@ def _guessIntegerType(container, name, value):


def _propertyContainerSet(container, name, value, typeMenu, *args):
"""Set a single Python value of unknown type"""
"""Set a single Python value of unknown type
"""
if hasattr(value, "__iter__") and not isinstance(value, (str, PropertySet, PropertyList)):
exemplar = value[0]
else:
Expand All @@ -288,7 +312,8 @@ def _propertyContainerSet(container, name, value, typeMenu, *args):


def _propertyContainerAdd(container, name, value, typeMenu, *args):
"""Add a single Python value of unknown type"""
"""Add a single Python value of unknown type
"""
if hasattr(value, "__iter__"):
exemplar = value[0]
else:
Expand Down Expand Up @@ -358,7 +383,7 @@ def get(self, name, default=None):
Parameters
----------
name : ``str``
name : `str`
Name of item
default : `object`, optional
Default value to use if the named item is not present.
Expand Down
15 changes: 10 additions & 5 deletions python/lsst/daf/base/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def dt_representer(dumper, data):

def pl_representer(dumper, data):
"""Represent an lsst.daf.base.PropertyList as an ordered sequence of
name/type/value/comment lists)"""
name/type/value/comment lists)
"""
# Turn the tuples into lists for cleaner representation in yaml
result = getPropertyListState(data, asLists=True)
return dumper.represent_sequence('lsst.daf.base.PropertyList', result,
Expand All @@ -78,7 +79,8 @@ def pl_representer(dumper, data):

def ps_representer(dumper, data):
"""Represent an lsst.daf.base.PropertySet as a mapping from names to
type/value pairs."""
type/value pairs.
"""
# Turn the tuples into lists for cleaner representation in yaml
result = getPropertySetState(data, asLists=True)
return dumper.represent_sequence('lsst.daf.base.PropertySet', result,
Expand All @@ -95,14 +97,16 @@ def ps_representer(dumper, data):

def dt_constructor(loader, node):
"""Construct an lsst.daf.base.DateTime from an ISO8601-formatted string in
TAI"""
TAI
"""
dt = loader.construct_scalar(node)
return DateTime(str(dt), DateTime.TAI)


def pl_constructor(loader, node):
"""Construct an lsst.daf.base.PropertyList from a YAML pickle-like
structure."""
structure.
"""
pl = PropertyList()
yield pl
state = loader.construct_sequence(node, deep=True)
Expand All @@ -111,7 +115,8 @@ def pl_constructor(loader, node):

def ps_constructor(loader, node):
"""Construct an lsst.daf.base.PropertyList from a YAML pickle-like
structure."""
structure.
"""
ps = PropertySet()
yield ps
state = loader.construct_sequence(node, deep=True)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_PropertyList.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

class FloatSubClass(float):
"""Intended to be something like numpy.float64, without introducing a
dependency on numpy"""
dependency on numpy
"""
pass


class PropertyListTestCase(unittest.TestCase):
"""A test case for PropertyList."""
"""A test case for PropertyList.
"""

def testConstruct(self):
apl = dafBase.PropertyList()
Expand Down
9 changes: 6 additions & 3 deletions tests/test_PropertySet_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@


class PropertySetTestCase(unittest.TestCase):
"""A test case for PropertySet."""
"""A test case for PropertySet.
"""

def testConstruct(self):
ps = dafBase.PropertySet()
Expand Down Expand Up @@ -308,7 +309,8 @@ def testCopy(self):


class FlatTestCase(unittest.TestCase):
"""A test case for flattened PropertySets."""
"""A test case for flattened PropertySets.
"""

def testConstruct(self):
ps = dafBase.PropertySet(flat=True)
Expand Down Expand Up @@ -750,7 +752,8 @@ def testvariousThrows(self):
ps.remove("int.sub")

def testIntegerRanges(self):
"""Test that the ranges of the various integer types is as expected"""
"""Test that the ranges of the various integer types is as expected
"""
ps = dafBase.PropertySet()
minI32 = -2**31
maxI32 = 2**31 - 1
Expand Down
9 changes: 6 additions & 3 deletions tests/test_dateTime.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@


class DateTimeTestCase(unittest.TestCase):
"""A test case for DateTime."""
"""A test case for DateTime.
"""

def setUp(self):
self.timeScales = (DateTime.TAI, DateTime.TT, DateTime.UTC)
Expand Down Expand Up @@ -114,7 +115,8 @@ def testIsoEpoch(self):
self.assertEqual(ts.toString(ts.UTC), "1970-01-01T00:00:00.000000000Z")

def testIsoUTCBasic(self):
"""Test basic ISO string input and output of UTC dates"""
"""Test basic ISO string input and output of UTC dates
"""
for dateSep in ("-", ""): # "-" date separator is optional
for timeSep in (":", ""): # ":" time separator is optional
for decPt in (".", ","): # "." or "," may be used as decimal point
Expand All @@ -126,7 +128,8 @@ def testIsoUTCBasic(self):
self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.314159265Z")

def testIsoNonUTCBasics(self):
"""Test basic ISO string input and output of TAI and TT dates"""
"""Test basic ISO string input and output of TAI and TT dates
"""
for scale in (DateTime.TAI, DateTime.TT):
for dateSep in ("-", ""): # "-" date separator is optional
for timeSep in (":", ""): # ":" time separator is optional
Expand Down
6 changes: 4 additions & 2 deletions tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def testYamlPL(self):
self.assertEqual(apl, apl2)

def testYamlNest(self):
"""Test nested property sets"""
"""Test nested property sets
"""
ps = lsst.daf.base.PropertySet()
ps.setBool("bool", True)
ps.setShort("short", 42)
Expand Down Expand Up @@ -124,7 +125,8 @@ def testYamlDateTime(self):
self.assertEqual(ts, ts2)

def testLoader(self):
"""Test loading of reference YAML files"""
"""Test loading of reference YAML files
"""
# Old and new serialization of a propertyList
with open(os.path.join(TESTDIR, "data", "fitsheader-tuple.yaml")) as fd:
old = yaml.load(fd, Loader=yaml.Loader)
Expand Down

0 comments on commit 2fe3899

Please sign in to comment.