terrakio-core 0.2.4__py3-none-any.whl → 0.2.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of terrakio-core might be problematic. Click here for more details.
- terrakio_core/client.py +43 -2
- {terrakio_core-0.2.4.dist-info → terrakio_core-0.2.6.dist-info}/METADATA +1 -1
- {terrakio_core-0.2.4.dist-info → terrakio_core-0.2.6.dist-info}/RECORD +5 -5
- {terrakio_core-0.2.4.dist-info → terrakio_core-0.2.6.dist-info}/WHEEL +0 -0
- {terrakio_core-0.2.4.dist-info → terrakio_core-0.2.6.dist-info}/top_level.txt +0 -0
terrakio_core/client.py
CHANGED
|
@@ -8,6 +8,7 @@ import aiohttp
|
|
|
8
8
|
import pandas as pd
|
|
9
9
|
import geopandas as gpd
|
|
10
10
|
import xarray as xr
|
|
11
|
+
import nest_asyncio
|
|
11
12
|
from shapely.geometry import shape, mapping
|
|
12
13
|
from shapely.geometry.base import BaseGeometry as ShapelyGeometry
|
|
13
14
|
|
|
@@ -18,6 +19,7 @@ class BaseClient:
|
|
|
18
19
|
auth_url: Optional[str] = "https://dev-au.terrak.io",
|
|
19
20
|
quiet: bool = False, config_file: Optional[str] = None,
|
|
20
21
|
verify: bool = True, timeout: int = 60):
|
|
22
|
+
nest_asyncio.apply()
|
|
21
23
|
self.quiet = quiet
|
|
22
24
|
self.verify = verify
|
|
23
25
|
self.timeout = timeout
|
|
@@ -519,7 +521,24 @@ class BaseClient:
|
|
|
519
521
|
self.auth_client.session.close()
|
|
520
522
|
# Close aiohttp session if it exists
|
|
521
523
|
if self._aiohttp_session and not self._aiohttp_session.closed:
|
|
522
|
-
|
|
524
|
+
try:
|
|
525
|
+
nest_asyncio.apply()
|
|
526
|
+
asyncio.run(self.close_async())
|
|
527
|
+
except ImportError:
|
|
528
|
+
try:
|
|
529
|
+
asyncio.run(self.close_async())
|
|
530
|
+
except RuntimeError as e:
|
|
531
|
+
if "cannot be called from a running event loop" in str(e):
|
|
532
|
+
# In Jupyter, we can't properly close the async session
|
|
533
|
+
# Log a warning or handle gracefully
|
|
534
|
+
import warnings
|
|
535
|
+
warnings.warn("Cannot properly close aiohttp session in Jupyter environment. "
|
|
536
|
+
"Consider using 'await client.close_async()' instead.")
|
|
537
|
+
else:
|
|
538
|
+
raise
|
|
539
|
+
except RuntimeError:
|
|
540
|
+
# Event loop may already be closed, ignore
|
|
541
|
+
pass
|
|
523
542
|
|
|
524
543
|
def __enter__(self):
|
|
525
544
|
return self
|
|
@@ -841,7 +860,28 @@ class BaseClient:
|
|
|
841
860
|
geopandas.GeoDataFrame: GeoDataFrame with added columns for results, or None if inplace=True
|
|
842
861
|
"""
|
|
843
862
|
import asyncio
|
|
844
|
-
|
|
863
|
+
|
|
864
|
+
# Check if we're in a Jupyter environment or already have an event loop
|
|
865
|
+
try:
|
|
866
|
+
loop = asyncio.get_running_loop()
|
|
867
|
+
# We're in an async context (like Jupyter), use create_task
|
|
868
|
+
nest_asyncio.apply()
|
|
869
|
+
result = asyncio.run(self.zonal_stats_async(gdb, expr, conc, inplace, output))
|
|
870
|
+
except RuntimeError:
|
|
871
|
+
# No running event loop, safe to use asyncio.run()
|
|
872
|
+
result = asyncio.run(self.zonal_stats_async(gdb, expr, conc, inplace, output))
|
|
873
|
+
except ImportError:
|
|
874
|
+
# nest_asyncio not available, try alternative approach
|
|
875
|
+
try:
|
|
876
|
+
loop = asyncio.get_running_loop()
|
|
877
|
+
# Create task in existing loop
|
|
878
|
+
task = loop.create_task(self.zonal_stats_async(gdb, expr, conc, inplace, output))
|
|
879
|
+
# This won't work directly - we need a different approach
|
|
880
|
+
raise RuntimeError("Cannot run async code in Jupyter without nest_asyncio. Please install: pip install nest-asyncio")
|
|
881
|
+
except RuntimeError:
|
|
882
|
+
# No event loop, use asyncio.run
|
|
883
|
+
result = asyncio.run(self.zonal_stats_async(gdb, expr, conc, inplace, output))
|
|
884
|
+
|
|
845
885
|
# Ensure aiohttp session is closed after running async code
|
|
846
886
|
try:
|
|
847
887
|
if self._aiohttp_session and not self._aiohttp_session.closed:
|
|
@@ -849,6 +889,7 @@ class BaseClient:
|
|
|
849
889
|
except RuntimeError:
|
|
850
890
|
# Event loop may already be closed, ignore
|
|
851
891
|
pass
|
|
892
|
+
|
|
852
893
|
return result
|
|
853
894
|
|
|
854
895
|
# Group access management protected methods
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
terrakio_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
terrakio_core/auth.py,sha256=Nuj0_X3Hiy17svYgGxrSAR-LXpTlP0J0dSrfMnkPUbI,7717
|
|
3
|
-
terrakio_core/client.py,sha256=
|
|
3
|
+
terrakio_core/client.py,sha256=ykbgD_81HAtZXY9wDpPKR9audo5Xkh1Mh0HQcLPgyKs,46878
|
|
4
4
|
terrakio_core/config.py,sha256=AwJ1VgR5K7N32XCU5k7_Dp1nIv_FYt8MBonq9yKlGzA,2658
|
|
5
5
|
terrakio_core/dataset_management.py,sha256=hhO35fwStS6HYFQdKP9wkr3DxHgjvpctmIU8UWH6w6U,8742
|
|
6
6
|
terrakio_core/exceptions.py,sha256=9S-I20-QiDRj1qgjFyYUwYM7BLic_bxurcDOIm2Fu_0,410
|
|
@@ -8,7 +8,7 @@ terrakio_core/group_access_management.py,sha256=NJ7SX4keUzZAUENmJ5L6ynKf4eRlqtyi
|
|
|
8
8
|
terrakio_core/mass_stats.py,sha256=AqYJsd6nqo2BDh4vEPUDgsv4T0UR1_TPDoXa3WO3gTU,9284
|
|
9
9
|
terrakio_core/space_management.py,sha256=wlUUQrlj_4U_Lpjn9lbF5oj0Rv3NPvvnrd5mWej5kmA,4211
|
|
10
10
|
terrakio_core/user_management.py,sha256=MMNWkz0V_9X7ZYjjteuRU4H4W3F16iuQw1dpA2wVTGg,7400
|
|
11
|
-
terrakio_core-0.2.
|
|
12
|
-
terrakio_core-0.2.
|
|
13
|
-
terrakio_core-0.2.
|
|
14
|
-
terrakio_core-0.2.
|
|
11
|
+
terrakio_core-0.2.6.dist-info/METADATA,sha256=K-2CqTD95e3a7TgXSEk2JTadmVLQFbDdppRXBrMYyao,1405
|
|
12
|
+
terrakio_core-0.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
13
|
+
terrakio_core-0.2.6.dist-info/top_level.txt,sha256=5cBj6O7rNWyn97ND4YuvvXm0Crv4RxttT4JZvNdOG6Q,14
|
|
14
|
+
terrakio_core-0.2.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|