Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2Provides a function to open the system browser to either search or go directly 

3to a function's reference 

4""" 

5from statsmodels.compat.pandas import deprecate_kwarg 

6 

7import webbrowser 

8from urllib.parse import urlencode 

9 

10from statsmodels import __version__ 

11 

12BASE_URL = 'https://www.statsmodels.org/' 

13 

14 

15def _generate_url(func, stable): 

16 """ 

17 Parse inputs and return a correctly formatted URL or raises ValueError 

18 if the input is not understandable 

19 """ 

20 url = BASE_URL 

21 if stable: 

22 url += 'stable/' 

23 else: 

24 url += 'devel/' 

25 

26 if func is None: 

27 return url 

28 elif isinstance(func, str): 

29 url += 'search.html?' 

30 url += urlencode({'q': func}) 

31 url += '&check_keywords=yes&area=default' 

32 else: 

33 try: 

34 func = func 

35 func_name = func.__name__ 

36 func_module = func.__module__ 

37 if not func_module.startswith('statsmodels.'): 

38 raise ValueError('Function must be from statsmodels') 

39 url += 'generated/' 

40 url += func_module + '.' + func_name + '.html' 

41 except AttributeError: 

42 raise ValueError('Input not understood') 

43 return url 

44 

45 

46@deprecate_kwarg('arg', 'func') 

47def webdoc(func=None, stable=None): 

48 """ 

49 Opens a browser and displays online documentation 

50 

51 Parameters 

52 ---------- 

53 func : {str, callable} 

54 Either a string to search the documentation or a function 

55 stable : bool 

56 Flag indicating whether to use the stable documentation (True) or 

57 the development documentation (False). If not provided, opens 

58 the stable documentation if the current version of statsmodels is a 

59 release 

60 

61 Examples 

62 -------- 

63 >>> import statsmodels.api as sm 

64 

65 Documentation site 

66 

67 >>> sm.webdoc() 

68 

69 Search for glm in docs 

70 

71 >>> sm.webdoc('glm') 

72 

73 Go to current generated help for OLS 

74 

75 >>> sm.webdoc(sm.OLS, stable=False) 

76 

77 Notes 

78 ----- 

79 By default, open stable documentation if the current version of 

80 statsmodels is a release. Otherwise opens the development documentation. 

81 

82 Uses the default system browser. 

83 """ 

84 stable = __version__ if 'dev' not in __version__ else stable 

85 url_or_error = _generate_url(func, stable) 

86 webbrowser.open(url_or_error) 

87 return None