looks like `is` might be the way to check for `NULL` in Cython

http://docs.cython.org/src/tutorial/clibraries.html#testing-the-result

so maybe change to `if f is NULL`

also can you change the error message to say something about periods? something simple like "Unrecognizable period code: {the_code}"