Search code examples
pythonjupyter-notebookspatialgeopandas

Spatial join crashes when called from script


I have a geopandas spatial join statement that runs fine when performing from Jupyter Notebook. However, when called from a windows task scheduler script (pointing to a .bat file every morning at 07:00) the logfile I create stops giving output precisely before the call to spatial join.

geodf = geodf[geodf.geometry.notnull()]
print(len(geodf) - before, 'geometries were dropped that had null values')

# spatial join the dataframe with the airspace will 'place' the points in the right airspace
df3 = geodf.sjoin(AirspaceNL, how='left' )
print('spatial join done with AirspaceNL') 

The statement geodf = geodf[geodf.geometry.notnull()] is executed without problems. I can read the 'geometries were dropped ...' etc. in the logfile. Then it stops. Apparently the spatial join of the next statement is the problem? Note that when run directly from Jupyter Notebook, all is fine.

Well... not all is fine. In Jupyter Notebook, I get the following warning with pink background:

C:\Users\bruggenj\AppData\Roaming\Python\Python38\site-packages\pandas\core\reshape\merge.py:1204: RuntimeWarning: invalid value encountered in cast
  if not (lk == lk.astype(rk.dtype))[~np.isnan(lk)].all():

What could possibly be the issue?


Solution

  • Indeed my last hunch was correct. The version of GeoPandas running on this other machine was out of date and did not have sjoin as an attrtibute. Updating the package with pip install -U geopandas in a Conda command window on the computer that runs my script solved it.

    Sorry for bothering you with my stupidity...