Code Monkey home page Code Monkey logo

coding-for-economists's Introduction

coding-for-economists

Binder

This readme is intended to help those contributing to or editing the book, not those trying to follow it. To read or use the book, head to the coding for economists website. You can use the book interactively via the following options, all available via the link above:

  • download pages to your computer as jupyter notebooks
  • run pages in Google Colab through your browser
  • run pages in Binder through your browser

Dev

These instructions are only for developers working on the book.

Setting up the Environment

In principle, the environment can be installed using

conda env create -f environment.yml

on the command line. However, the large number of pip dependencies causes conda's env create function to hang and the only way to work around it seems to be to allow conda to install conda packages and then install the pip packages manually. After installing the conda environment but before pip installing packages individually, activate using conda activate codeforecon, and use

python3.8 -m ipykernel install --user --name=codeforecon

to install a new named ipykernel. To ensure that Jupyter notebooks are running the correct kernel, open them in Jupyter notebook server and change the kernel there to 'codeforecon' and save it.

Some extra assets associated with packages are required. You will need to run python -m spacy download en_core_web_sm to download the spacy model. There are also several models needed for nltk.

Building the Book

To build the book using Jupyter books use

jupyter-book build .

Once this command is run, you should be able to look at the HTML files for the book locally on your computer.

Note that, due to package conflicts, several pages may not compile when taking this approach. One work around is to manually run troublesome notebooks and, when jupyterbook encounters a problem when executing them to build the book, it will pick up the notebook at the last point it was successfully manually executed.

Uploading Built Files

See here for how to upload revised HTML files, but the key command is

ghp-import -n -p -f _build/html

To perform the pre-commit checks, use

pre-commit run --all-files

Pre-commit

Pre-commit is currently configured to:

  • check for large added files
  • strip outputs from notebooks
  • apply the black code formatter to .py and .ipnb scripts

If black-nb finds a pre-commit error that is difficult to diagnose, a tip is to convert it to a regular script to find the problem, using, for example,

jupytext --to py data-intro.ipynb

Good to Know

If you get a

File "python3.8/site-packages/myst_nb/parser.py", line 139, in nb_to_tokens
    start_line = source_map[cell_index] if source_map else (cell_index + 1) * 10000
IndexError: list index out of range

error then it may be that the notebook metadata has gone awry. If you can isolate the notebook, you can refresh the metadata by running:

jupytext --to py bad_notebook.ipynb
jupytext --to notebook bad_notebook.py

This will overwrite the existing notebook!

coding-for-economists's People

Contributors

aeturrell avatar lukestein avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.