malcolmSQ commited on
Commit ·
c40d9fd
1
Parent(s): 9060008
fix: move to_native to top of file to guarantee scope and prevent NameError
Browse files- dashboard/app.py +21 -0
dashboard/app.py
CHANGED
|
@@ -31,6 +31,27 @@ SPECIES_DISPLAY_NAMES = {
|
|
| 31 |
'species_B': 'Avicennia germinans'
|
| 32 |
}
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Helper to update planting schedule in a config file
|
| 35 |
def update_planting_schedule(config_path, year_areas):
|
| 36 |
with open(config_path) as f:
|
|
|
|
| 31 |
'species_B': 'Avicennia germinans'
|
| 32 |
}
|
| 33 |
|
| 34 |
+
def to_native(obj):
|
| 35 |
+
if isinstance(obj, pd.DataFrame):
|
| 36 |
+
obj = obj.applymap(lambda x: to_native(x))
|
| 37 |
+
obj.index = obj.index.map(to_native)
|
| 38 |
+
obj.columns = obj.columns.map(to_native)
|
| 39 |
+
return obj
|
| 40 |
+
elif isinstance(obj, pd.Series):
|
| 41 |
+
obj = obj.map(to_native)
|
| 42 |
+
obj.index = obj.index.map(to_native)
|
| 43 |
+
return obj
|
| 44 |
+
elif isinstance(obj, dict):
|
| 45 |
+
return {to_native(k): to_native(v) for k, v in obj.items()}
|
| 46 |
+
elif isinstance(obj, list):
|
| 47 |
+
return [to_native(x) for x in obj]
|
| 48 |
+
elif isinstance(obj, tuple):
|
| 49 |
+
return tuple(to_native(x) for x in obj)
|
| 50 |
+
elif isinstance(obj, (np.generic, np.ndarray)):
|
| 51 |
+
return obj.item() if obj.size == 1 else obj.tolist()
|
| 52 |
+
else:
|
| 53 |
+
return obj
|
| 54 |
+
|
| 55 |
# Helper to update planting schedule in a config file
|
| 56 |
def update_planting_schedule(config_path, year_areas):
|
| 57 |
with open(config_path) as f:
|