Skip to content

Commit ab5df41

Browse files
mmckyclaude
andcommitted
FIX: seven source-side defects found via the translation review
Addresses the defects reported in #602, which were surfaced by Copilot's review of the Malayalam translation PRs and traced back to the English source. Code correctness (pandas.md): * replace `type(x) != str` with `not isinstance(x, str)` in both `.map()` examples, so `str` subclasses are treated as strings * replace `np.isnan(x)` with `pd.isna(x)` in `replace_nan`, which tolerates `None`, `pd.NA` and `pd.NaT` where `np.isnan` raises `TypeError` * drop the dead `research.stlouisfed.org` URL from the prose introducing the FRED example; it now names `requests.get(url)`, matching the code cell directly below it Both edited cells were replayed against the lecture's own data: the rendered output and dtypes are byte-identical, so no cached notebook output moves. Typography and naming: * python_by_example.md: use single backticks for the four inline code spans written with triple backticks * functions.md: describe the call stack as a last-in, first-out (LIFO) data structure rather than a "First In Last Out (FILO) queue" * numpy.md: space after the `---` marker at line 218, matching the repo's dominant convention; `Numpy` -> `NumPy`; `discreteRV` -> `DiscreteRV` to match the class actually defined in the cell above Item 6 of #602 is not actioned: `df.query("cc + cg >= 80 & POP <= 20000")` is correct as written. `DataFrame.query` rewrites the `&` token to `and` before parsing, so the expression has boolean precedence and is equivalent to the parenthesised boolean-indexing example above it, as the prose claims. `**Part2**` at numpy.md:1432 is also fixed. It is the sibling of the reported `**Part1**` in the same exercise, and fixing only the reported line would have left the pair inconsistent. Closes #602 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent fb389e7 commit ab5df41

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

lectures/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ What happens here is that each successive call uses it's own *frame* in the *sta
451451

452452
* a frame is where the local variables of a given function call are held
453453
* stack is memory used to process function calls
454-
* a First In Last Out (FILO) queue
454+
* a last-in, first-out (LIFO) data structure
455455

456456
This example is somewhat contrived, since the first (iterative) solution would usually be preferred to the recursive solution.
457457

lectures/numpy.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ z
215215
See also `np.asarray`, which performs a similar function, but does not make
216216
a distinct copy of data already in a NumPy array.
217217

218-
To read in the array data from a text file containing numeric data use `np.loadtxt` ---see [the documentation](https://numpy.org/doc/stable/reference/routines.io.html) for details.
218+
To read in the array data from a text file containing numeric data use `np.loadtxt` --- see [the documentation](https://numpy.org/doc/stable/reference/routines.io.html) for details.
219219

220220

221221

@@ -1271,7 +1271,7 @@ you will understand.
12711271

12721272
There is a problem here, however.
12731273

1274-
Suppose that `q` is altered after an instance of `discreteRV` is
1274+
Suppose that `q` is altered after an instance of `DiscreteRV` is
12751275
created, for example by
12761276

12771277
```{code-cell} python3
@@ -1406,11 +1406,11 @@ F.plot(ax)
14061406
:label: np_ex4
14071407
```
14081408

1409-
Recall that [broadcasting](broadcasting) in Numpy can help us conduct element-wise operations on arrays with different number of dimensions without using `for` loops.
1409+
Recall that [broadcasting](broadcasting) in NumPy can help us conduct element-wise operations on arrays with different number of dimensions without using `for` loops.
14101410

14111411
In this exercise, try to use `for` loops to replicate the result of the following broadcasting operations.
14121412

1413-
**Part1**: Try to replicate this simple example using `for` loops and compare your results with the broadcasting operation below.
1413+
**Part 1**: Try to replicate this simple example using `for` loops and compare your results with the broadcasting operation below.
14141414

14151415
```{code-cell} python3
14161416
@@ -1429,7 +1429,7 @@ tags: [hide-output]
14291429
print(A)
14301430
```
14311431

1432-
**Part2**: Move on to replicate the result of the following broadcasting operation. Meanwhile, compare the speeds of broadcasting and the `for` loop you implement.
1432+
**Part 2**: Move on to replicate the result of the following broadcasting operation. Meanwhile, compare the speeds of broadcasting and the `for` loop you implement.
14331433

14341434
For this part of the exercise you can use the `tic`/`toc` functions from the `quantecon` library to time the execution.
14351435

lectures/pandas.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ df.apply(update_row, axis=1)
380380

381381
```{code-cell} ipython3
382382
# Round all decimal numbers to 2 decimal places
383-
df.map(lambda x : round(x,2) if type(x)!=str else x)
383+
df.map(lambda x : round(x,2) if not isinstance(x, str) else x)
384384
```
385385

386386
**Application: Missing Value Imputation**
@@ -403,8 +403,8 @@ We can use the `.map()` method again to replace all missing values with 0
403403
```{code-cell} ipython3
404404
# replace all NaN values by 0
405405
def replace_nan(x):
406-
if type(x)!=str:
407-
return 0 if np.isnan(x) else x
406+
if not isinstance(x, str):
407+
return 0 if pd.isna(x) else x
408408
else:
409409
return x
410410
@@ -536,7 +536,7 @@ In the second case, you can either
536536
* switch to another machine
537537
* solve your proxy problem by reading [the documentation](https://requests.readthedocs.io/en/latest/)
538538

539-
Assuming that all is working, you can now proceed to use the `source` object returned by the call `requests.get('https://research.stlouisfed.org/fred2/series/UNRATE/downloaddata/UNRATE.csv')`
539+
Assuming that all is working, you can now proceed to build the `source` object from the data returned by the call `requests.get(url)`
540540

541541
```{code-cell} ipython3
542542
url = 'https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23e1e9f0&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1318&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=UNRATE&scale=left&cosd=1948-01-01&coed=2024-06-01&line_color=%234572a7&link_values=false&line_style=solid&mark_type=none&mw=3&lw=2&ost=-99999&oet=99999&mma=0&fml=a&fq=Monthly&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2024-07-29&revision_date=2024-07-29&nd=1948-01-01'

lectures/python_by_example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,9 @@ plt.plot(ϵ_values)
380380
plt.show()
381381
```
382382

383-
A while loop will keep executing the code block delimited by indentation until the condition (```i < ts_length```) is satisfied.
383+
A while loop will keep executing the code block delimited by indentation until the condition (`i < ts_length`) is satisfied.
384384

385-
In this case, the program will keep adding values to the list ```ϵ_values``` until ```i``` equals ```ts_length```:
385+
In this case, the program will keep adding values to the list `ϵ_values` until `i` equals `ts_length`:
386386

387387
```{code-cell} python3
388388
i == ts_length #the ending condition for the while loop

0 commit comments

Comments
 (0)