@@ -1177,7 +1177,7 @@ class NumpyDocstringTest(BaseDocstringTest):
1177
1177
"""
1178
1178
Single line summary
1179
1179
1180
- :returns: * str* -- Extended
1180
+ :returns: :class:` str` -- Extended
1181
1181
description of return value
1182
1182
"""
1183
1183
), (
@@ -1193,7 +1193,7 @@ class NumpyDocstringTest(BaseDocstringTest):
1193
1193
"""
1194
1194
Single line summary
1195
1195
1196
- :returns: * str* -- Extended
1196
+ :returns: :class:` str` -- Extended
1197
1197
description of return value
1198
1198
"""
1199
1199
), (
@@ -1246,7 +1246,7 @@ class NumpyDocstringTest(BaseDocstringTest):
1246
1246
"""
1247
1247
Single line summary
1248
1248
1249
- :Yields: * str* -- Extended
1249
+ :Yields: :class:` str` -- Extended
1250
1250
description of yielded value
1251
1251
"""
1252
1252
), (
@@ -1262,7 +1262,7 @@ class NumpyDocstringTest(BaseDocstringTest):
1262
1262
"""
1263
1263
Single line summary
1264
1264
1265
- :Yields: * str* -- Extended
1265
+ :Yields: :class:` str` -- Extended
1266
1266
description of yielded value
1267
1267
"""
1268
1268
)]
@@ -1555,6 +1555,52 @@ def test_underscore_in_attribute_strip_signature_backslash(self):
1555
1555
1556
1556
self .assertEqual (expected , actual )
1557
1557
1558
+ def test_return_types (self ):
1559
+ docstring = dedent ("""
1560
+ Returns
1561
+ -------
1562
+ DataFrame
1563
+ a dataframe
1564
+ """ )
1565
+ expected = dedent ("""
1566
+ :returns: a dataframe
1567
+ :rtype: :class:`~pandas.DataFrame`
1568
+ """ )
1569
+ translations = {
1570
+ "DataFrame" : "~pandas.DataFrame" ,
1571
+ }
1572
+ config = Config (
1573
+ napoleon_use_param = True ,
1574
+ napoleon_use_rtype = True ,
1575
+ napoleon_preprocess_types = True ,
1576
+ napoleon_type_aliases = translations ,
1577
+ )
1578
+ actual = str (NumpyDocstring (docstring , config ))
1579
+ self .assertEqual (expected , actual )
1580
+
1581
+ def test_yield_types (self ):
1582
+ docstring = dedent ("""
1583
+ Example Function
1584
+
1585
+ Yields
1586
+ ------
1587
+ scalar or array-like
1588
+ The result of the computation
1589
+ """ )
1590
+ expected = dedent ("""
1591
+ Example Function
1592
+
1593
+ :Yields: :term:`scalar` or :class:`array-like <numpy.ndarray>` -- The result of the computation
1594
+ """ )
1595
+ translations = {
1596
+ "scalar" : ":term:`scalar`" ,
1597
+ "array-like" : ":class:`array-like <numpy.ndarray>`" ,
1598
+ }
1599
+ config = Config (napoleon_type_aliases = translations , napoleon_preprocess_types = True )
1600
+ app = mock .Mock ()
1601
+ actual = str (NumpyDocstring (docstring , config , app , "method" ))
1602
+ self .assertEqual (expected , actual )
1603
+
1558
1604
def test_raises_types (self ):
1559
1605
docstrings = [("""
1560
1606
Example Function
@@ -1719,6 +1765,34 @@ def test_raises_types(self):
1719
1765
("""
1720
1766
Example Function
1721
1767
1768
+ Raises
1769
+ ------
1770
+ CustomError
1771
+ If the dimensions couldn't be parsed.
1772
+
1773
+ """ , """
1774
+ Example Function
1775
+
1776
+ :raises package.CustomError: If the dimensions couldn't be parsed.
1777
+ """ ),
1778
+ ################################
1779
+ ("""
1780
+ Example Function
1781
+
1782
+ Raises
1783
+ ------
1784
+ AnotherError
1785
+ If the dimensions couldn't be parsed.
1786
+
1787
+ """ , """
1788
+ Example Function
1789
+
1790
+ :raises ~package.AnotherError: If the dimensions couldn't be parsed.
1791
+ """ ),
1792
+ ################################
1793
+ ("""
1794
+ Example Function
1795
+
1722
1796
Raises
1723
1797
------
1724
1798
:class:`exc.InvalidDimensionsError`
@@ -1731,7 +1805,11 @@ def test_raises_types(self):
1731
1805
:raises exc.InvalidArgumentsError:
1732
1806
""" )]
1733
1807
for docstring , expected in docstrings :
1734
- config = Config ()
1808
+ translations = {
1809
+ "CustomError" : "package.CustomError" ,
1810
+ "AnotherError" : ":py:exc:`~package.AnotherError`" ,
1811
+ }
1812
+ config = Config (napoleon_type_aliases = translations , napoleon_preprocess_types = True )
1735
1813
app = mock .Mock ()
1736
1814
actual = str (NumpyDocstring (docstring , config , app , "method" ))
1737
1815
self .assertEqual (expected , actual )
0 commit comments