Skip to content

Commit 1c7e427

Browse files
authored
feat: add intersphinx and autolink :)
2 parents 47587fe + b54cc31 commit 1c7e427

File tree

11 files changed

+57
-25
lines changed

11 files changed

+57
-25
lines changed

_static/css/styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

22
.navbar-header-items .navbar-header-items__center {
33
margin-left: 2em !important;
4+
}
5+
6+
.sphinx-codeautolink-a:link {
7+
text-decoration: underline;
8+
text-decoration-style: dotted;
49
}

clean-modular-code/activity-1/clean-code-activity-1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ df_combined.shape
186186

187187
```{dropdown} Hint 1 - built-in help
188188
If you want to look up a pandas function to get help, Jupyter Lab has built-in help.
189-
Enter `help(pd.DataFrame.iterrows)`.
189+
Enter `help(pd.DataFrame.iterrows)` to see the {meth}`documentation <pandas.DataFrame.iterrows>`.
190190
```
191191

192192
```{dropdown} Hint 2 - itterows and at

clean-modular-code/activity-3/clean-code-activity-3.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ all_papers_df = pd.concat(all_papers_list, axis=0, ignore_index=True)
160160

161161
## Activity 3, part 2: Add checks to the `format_date` function
162162

163-
The code below creates a `pd.DataFrame` with the first 15 publications in the JOSS sample `data.json` file. This is the first of 3 files you must process in your workflow.
163+
The code below creates a {class}`pandas.DataFrame` with the first 15 publications in the JOSS sample `data.json` file. This is the first of 3 files you must process in your workflow.
164164

165-
Your first task is to process and format the `published_date` column in the data to make it a `pandas.datetime` object. Having a date in a `datetime` format will allow you to do time-related analysis on your data, such as counting publications by month and year! The expected CrossRef published date should be:
165+
Your first task is to process and format the `published_date` column in the data to make it a {class}`pandas.Timestamp` object. Having a date in a `datetime` format like {class}`pandas.Timestamp` or {class}`datetime.datetime` will allow you to do time-related analysis on your data, such as counting publications by month and year! The expected CrossRef published date should be:
166166

167167
```json
168168
"published": {
@@ -195,7 +195,7 @@ In small groups, do the following:
195195

196196
+++ {"editable": true, "slideshow": {"slide_type": ""}, "tags": ["hide-output", "hide-cell"]}
197197

198-
### Format dates with `pandas.datetime`
198+
### Format dates with {func}`pandas.to_datetime`
199199

200200
Let's work on formatting dates so there is a consistent format in our dataframe. Python has a [string formatting language](https://docs.python.org/3/library/string.html#formatspec) that defines useful characters for formatting.
201201

@@ -362,13 +362,13 @@ format_date(joss_pubs_df["published_date"][13])
362362

363363
+++ {"editable": true, "slideshow": {"slide_type": ""}}
364364

365-
### How to apply functions to DataFrame values: `pandas.apply()`
365+
### How to apply functions to DataFrame values: `.apply()`
366366

367-
The `pandas.apply()` method allows you to apply any function to rows or columns in a `pandas.DataFrame`. For example, you can use it to perform operations on specific column or row values. When you use `.apply()`, you can specify whether you want to apply the function across columns `(axis=0)` (the default) or across rows `(axis=1)`.
367+
The {meth}`.apply() <pandas.DataFrame.apply>` method allows you to apply any function to rows or columns in a {class}`pandas.DataFrame`. For example, you can use it to perform operations on specific column or row values. When you use `.apply()`, you can specify whether you want to apply the function across columns `(axis=0)` (the default) or across rows `(axis=1)`.
368368

369369
For example, if you want to apply a function to each row of a DataFrame, you would use `df.apply(your_function, axis=1)`. This function is especially useful for applying logic that can’t be easily achieved with built-in pandas functions, allowing for more flexibility in data processing.
370370

371-
You can use `.apply` in pandas to efficiently replace `for loops` to process row and column values in a `pandas.DataFrame`.
371+
You can use `.apply` in pandas to efficiently replace `for loops` to process row and column values in a {class}`pandas.DataFrame`.
372372

373373
```python
374374
# Apply the format_date function to every row in the published_date column

clean-modular-code/python-dry-modular-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ For example,`print()` is a function used to write output to the Python console (
9292
Below, you will see the function that you looked at in the previous lesson. This is a custom function with a custom name.
9393

9494
```python
95-
def convert_to_kelvin(temperature_fahr)
95+
def convert_to_kelvin(temperature_fahr):
9696
"""Convert temperature in Fahrenheit to kelvin.
9797
9898
Parameters:

clean-modular-code/python-pep-8.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Most text editors allow you to set up guides to see how long your code is. You c
325325
* PEP 8 recommends organizing imports in the following order:
326326
327327
1. **Standard Library Imports**: These built-in modules come with Python, such as `os` and `glob`. You can find the full list [here](https://docs.python.org/3/library/index.html).
328-
2. **Third-Party Imports**: Libraries that you install via `pip`, like `numpy` and `pandas`.
328+
2. **Third-Party Imports**: Libraries that you install via `pip`, like {mod}`numpy` and {mod}`pandas`.
329329
3. **Local Imports**: Code or modules specific to your project.
330330
331331
Here’s an example following PEP 8 conventions:

code-workflow-logic/about-python-functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ Source: Francois Michonneau.
7171

7272
A well-defined function only does one thing but does it well and often in various contexts. Often, the operations in a good function are useful for many tasks.
7373

74-
Take, for instance, the **numpy** function called `mean()`, which computes mean values from a **numpy** array.
74+
Take, for instance, the **{mod}`numpy`** function called {func}`~numpy.mean`, which computes mean values from a **numpy** array.
7575

76-
This function only does one thing-- it computes a mean. However, you may use the `np.mean()` function many times in your code on multiple **numpy** arrays because it has been defined to take any **numpy** array as an input.
76+
This function only does one thing-- it computes a mean. However, you may use the {func}`np.mean() <numpy.mean>` function many times in your code on multiple **numpy** arrays because it has been defined to take any **numpy** array as an input.
7777

7878
For example:
7979
<!-- #endregion -->
@@ -88,7 +88,7 @@ np.mean(arr)
8888
```
8989

9090
<!-- #region editable=true slideshow={"slide_type": ""} -->
91-
The `np.mean()` function is modular, and it can be easily combined with other functions to accomplish various tasks.
91+
The {func}`numpy.mean()` function is modular, and it can be easily combined with other functions to accomplish various tasks.
9292

9393
When you write modular functions, you can reuse them for other workflows and projects. Some people even write their own **Python** packages for personal and professional use that contain custom functions for tasks that they have to complete regularly.
9494

code-workflow-logic/python-conditionals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ else:
9191
# Set x to 0
9292
x = 0
9393

94-
# Compare x to 10; notice comparison is two equal signs and assignment is one eaual sign.
94+
# Compare x to 10; notice comparison is two equal signs and assignment is one equal sign.
9595
if x == 10:
9696
print("x is equal to 10.")
9797
else:

code-workflow-logic/python-functions-multi-parameters.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def function_name(data_1, data_2):
5050
```
5151

5252
<!-- #region -->
53-
When the function is called, a user can provide any value for `data_1` or `data_2` as input for that parameter (e.g., single-value variable, list, **numpy** array, **pandas** data frame column).
53+
When the function is called, a user can provide any value for `data_1` or `data_2` as input for that parameter (e.g., single-value variable, list, {class}`numpy.ndarray`, {class}`pandas.DataFrame` column).
5454

5555

5656
## Write a Function with Multiple Parameters in Python
@@ -66,6 +66,7 @@ def multiply_values():
6666

6767
Next, provide two placeholder variable names for the input parameters, as shown below.
6868

69+
6970
```python
7071
def multiply_values(x, y):
7172
```
@@ -163,7 +164,6 @@ Use placeholder variable names that highlight the purpose of each parameter:
163164
def mean_mm_to_in(data_mm, axis_value):
164165
```
165166

166-
167167
Next, add the code to first calculate the mean of the input array along a specified axis, and then to convert the mean values from millimeters to inches.
168168

169169
First, add the code line to calculate a mean along a specified axis.
@@ -387,8 +387,8 @@ monthly_mean_in
387387
You can also write multi-parameter functions to combine other tasks into one function, such as downloading and reading data files into a **pandas** dataframe.
388388

389389
Think about the code that you need to include in the function:
390-
1. download data file from URL: `et.data.get_data(url=file_url)`
391-
2. read data file into **pandas** dataframe: `pd.read_csv(path)`
390+
1. download data file from URL: {func}`et.data.get_data(url=file_url) <earthpy.data.get_data>`
391+
2. read data file into **pandas** dataframe: {func}`pd.read_csv(path) <pandas.read_csv>`
392392

393393
From this code, you can see that you will need two input parameters for the combined function:
394394
1. the URL to the data file

code-workflow-logic/write-python-functions.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,19 @@ In **Python**, the required parameters are provided within parenthesis `()`, as
8888

8989
```python
9090
def function_name(parameter):
91-
```
91+
```
9292

9393
You can define an input parameter for a function using a placeholder variable, such as `data`, which represents the value or object that will be acted upon in the function.
9494

95-
9695
```python
9796
def function_name(data):
98-
```
97+
```
9998

10099
You can define a function using multiple parameters.
101100

102-
103101
```python
104102
def add_numbers(num_1, num_2):
105-
```
106-
103+
```
107104

108105
### Return Statement
109106

@@ -214,7 +211,7 @@ Can the function `mm_to_in()` to take a list as an input? Look again at the code
214211
<!-- #region editable=true slideshow={"slide_type": ""} -->
215212
## Call `help` on a custom function
216213

217-
Just like you can call `help()` on a function provided by a **Python** package such as **pandas** (e.g. `help(pd.DataFrame)`, you can also call `help()` on custom functions.
214+
Just like you can call `help()` on a function provided by a **Python** package such as **{mod}`pandas`** (e.g. {class}`help(pd.DataFrame) <pandas.DataFrame>`), you can also call `help()` on your own custom functions.
218215
<!-- #endregion -->
219216

220217
```python editable=true slideshow={"slide_type": ""}
@@ -231,7 +228,7 @@ help(add_numbers)
231228
<!-- #region editable=true slideshow={"slide_type": ""} -->
232229
Notice that when you call `help()` on custom functions, you will see the docstring that was provided in the function definition.
233230

234-
The `help()` results for `np.mean` are simply longer because the docstring contains more information, such as sections for Notes and Examples.
231+
The `help()` results for {func}`np.mean <numpy.mean>` are simply longer because the docstring contains more information, such as sections for Notes and Examples.
235232

236233
Combining related function calls into a single line of code allows you to write code that is much more efficient and less repetitive, assisting you in writing DRY code in **Python**.
237234

conf.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"sphinxext.opengraph",
5959
"sphinx_favicon",
6060
"sphinx.ext.todo",
61+
"sphinx_codeautolink",
6162
]
6263

6364
# colon fence for card support in md
@@ -174,3 +175,31 @@
174175

175176
# myst nb extension used to execute notebooks
176177
nb_execution_mode = "auto"
178+
179+
# ------------------
180+
# Intersphinx & code linking
181+
182+
intersphinx_mapping = {
183+
"python": ("https://docs.python.org/3", None),
184+
"numpy": ("https://numpy.org/doc/stable/", None),
185+
"pandas": ('https://pandas.pydata.org/docs/', None),
186+
"earthpy": ("https://earthpy.readthedocs.io/en/latest/", None),
187+
"matplotlib": ('https://matplotlib.org/stable/', None),
188+
}
189+
190+
codeautolink_global_preface = """
191+
import numpy as np
192+
import pandas as pd
193+
import os
194+
"""
195+
codeautolink_concat_default=True
196+
197+
# suppress all codeautolink warnings, we don't really care if it's busted
198+
suppress_warnings = [
199+
"codeautolink.clean_block",
200+
"codeautolink.parse_block",
201+
"codeautolink.import_star",
202+
"codeautolink.match_block",
203+
"codeautolink.match_name",
204+
"codeautolink.failed_resolve",
205+
]

0 commit comments

Comments
 (0)