Skip to content

Convert numpy scalars to python objects before dumping to yaml #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/problem_bank_scripts/problem_bank_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ def defdict_to_dict(defdict, finaldict):
v[k2] = dict(sorted(v2.items(), key=lambda i: i[0]))

finaldict[k] = v
# Somewhere around Aug 2024, something changed in how objects were serialized and anything stored as a `numpy` object wasn't correctly parsed by `pyyaml`
# See here for our history on this: (https://moosvilab.ok.ubc.ca/moosvilab/pl/zfp63dh6hjy5zdkzemzmtzqffr)
# And the jupyterbook PR where this was also addressed: https://github.com/jupyter-book/jupyter-book/pull/2167

elif hasattr(v, "dtype"):
try:
finaldict[k] = v.item()
except Exception:
finaldict[k] = v
else:
finaldict[k] = v
return finaldict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,7 @@ myst:
v: '2.50'
p: '4'
correct_answers:
part1_ans: !!python/object/apply:numpy.core.multiarray.scalar
- !!python/object/apply:numpy.dtype
args:
- f8
- false
- true
state: !!python/tuple
- 3
- <
- null
- null
- null
- -1
- -1
- 0
- !!binary |
ZVy1Q2Xubj8=
part1_ans: 0.0037757852384561635
part1_ans_str: '3.78e-03'

---
Expand Down
Loading