python

geodataframe is not defined

geodataframe is not defined Question: I’m working with Jupiter and ipywidgets and Ipyleaflet , trying to draw polygons on a map and saving to a geodataframe. I have the following in a notebook cell: zoom = 15 from ipywidgets import Output, interact import ipywidgets from __future__ import print_function import ipyleaflet import geopandas as gpd import …

Total answers: 2

jit – "Failed in nopython mode pipeline" error, despite not using nopython in numba

jit – "Failed in nopython mode pipeline" error, despite not using nopython in numba Question: I am using value function iteration to solve a complex dynamic programming problem with many states. I want to use numba/jit to speed up my code (and eventually parallelize the for loops). When I use the @jit decorator in my …

Total answers: 1

Why 00 is a valid integer in Python?

Why 00 is a valid integer in Python? Question: In the Python documentation : integer ::= decinteger | bininteger | octinteger | hexinteger decinteger ::= nonzerodigit (["_"] digit)* | "0"+ (["_"] "0")* bininteger ::= "0" ("b" | "B") (["_"] bindigit)+ octinteger ::= "0" ("o" | "O") (["_"] octdigit)+ hexinteger ::= "0" ("x" | "X") (["_"] …

Total answers: 1

What's the difference between np.divide(x, y) and x/y in Python3?

What's the difference between np.divide(x, y) and x/y in Python3? Question: I recently found a bug in my code that I was able to fix by replacing np.divide(x, y) with x / y. I was under the impression that np.divide(x, y) was equivalent to x / y (it says as much in the numpy documentation). …

Total answers: 1

by_alias parameter on model_dump() is being ignored

by_alias parameter on model_dump() is being ignored Question: In the following code, we see that the field id is indeed created with the alias of user_id when we print the model_fields. However, when I then call model_dump(alias=True), the returned dict has an id key, but does not have a user_id key as I am expecting. …

Total answers: 2

Problems with reciprocal of an dictionary

Problems with reciprocal of an dictionary Question: given dict: weights = {"A":16, "B": 3, "C": 5) I want to have the reciprocal of the values. Output: weights_dict_reci = {"A":0,0625, "B": 0,3333333, "C": 0,2) So far I tried: weights_dict_reci = {value: 1 / weights_dict[value] for value in weights_dict} and for key in weights_dict: weights_dict[key] = 1 …

Total answers: 2

python/sage: how to get the last expression?

python/sage: how to get the last expression? Question: If I do in Jupiter (in both python and sage) something like: a = 42 b = 43 a + b it will, somehow, manage to understand that this process returns the value a + b, i.e. 85 here: Similarly, if I just do: a = 42 …

Total answers: 2

pytest, xdist, and sharing generated file dependencies

pytest, xdist, and sharing generated file dependencies Question: I have multiple tests that need require an expensive-to-generate file. I’d like the file to be re-generated on every test run, but no more than once. To complicate the matter, both these tests as well as the file depend on an input parameter. def expensive(param) -> Path: …

Total answers: 1