You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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>
Copy file name to clipboardExpand all lines: lectures/numpy.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -215,7 +215,7 @@ z
215
215
See also `np.asarray`, which performs a similar function, but does not make
216
216
a distinct copy of data already in a NumPy array.
217
217
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.
219
219
220
220
221
221
@@ -1271,7 +1271,7 @@ you will understand.
1271
1271
1272
1272
There is a problem here, however.
1273
1273
1274
-
Suppose that `q` is altered after an instance of `discreteRV` is
1274
+
Suppose that `q` is altered after an instance of `DiscreteRV` is
1275
1275
created, for example by
1276
1276
1277
1277
```{code-cell} python3
@@ -1406,11 +1406,11 @@ F.plot(ax)
1406
1406
:label: np_ex4
1407
1407
```
1408
1408
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.
1410
1410
1411
1411
In this exercise, try to use `for` loops to replicate the result of the following broadcasting operations.
1412
1412
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.
1414
1414
1415
1415
```{code-cell} python3
1416
1416
@@ -1429,7 +1429,7 @@ tags: [hide-output]
1429
1429
print(A)
1430
1430
```
1431
1431
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.
1433
1433
1434
1434
For this part of the exercise you can use the `tic`/`toc` functions from the `quantecon` library to time the execution.
Copy file name to clipboardExpand all lines: lectures/pandas.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -380,7 +380,7 @@ df.apply(update_row, axis=1)
380
380
381
381
```{code-cell} ipython3
382
382
# 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)
384
384
```
385
385
386
386
**Application: Missing Value Imputation**
@@ -403,8 +403,8 @@ We can use the `.map()` method again to replace all missing values with 0
403
403
```{code-cell} ipython3
404
404
# replace all NaN values by 0
405
405
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
408
408
else:
409
409
return x
410
410
@@ -536,7 +536,7 @@ In the second case, you can either
536
536
* switch to another machine
537
537
* solve your proxy problem by reading [the documentation](https://requests.readthedocs.io/en/latest/)
538
538
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)`
0 commit comments