Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set nopython=False in numba.jit #535

Merged
merged 2 commits into from
Aug 4, 2023
Merged

Conversation

robna
Copy link
Contributor

@robna robna commented Jul 27, 2023

Hello! Please make sure to check all these boxes before submitting a Pull Request
(PR). Once you have checked the boxes, feel free to remove all text except the
justification in point 5.

  1. You have run tests on this submission locally using pytest on your changes. Continuous integration will be run on all PRs with GitHub Actions, but it is good practice to test changes locally prior to a making a PR.
  2. This pull request is directed to the pysal/master branch.
  3. This pull introduces new functionality covered by
    docstrings and
    unittests?
  4. You have assigned a
    reviewer
    and added relevant labels
  5. The justification for this PR is: just doing what the deprecations warning says: @jit decorators in alpha_shapes.py that are currently without any arguments now explicitly specify nopython=False

Closes #526

@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Merging #535 (0281ca6) into main (a2e3902) will increase coverage by 0.1%.
The diff coverage is 100.0%.

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #535     +/-   ##
=======================================
+ Coverage   79.9%   79.9%   +0.1%     
=======================================
  Files        113     113             
  Lines      13135   13133      -2     
=======================================
+ Hits       10491   10498      +7     
+ Misses      2644    2635      -9     
Files Changed Coverage Δ
libpysal/cg/alpha_shapes.py 87.2% <100.0%> (ø)
libpysal/cg/voronoi.py 78.6% <100.0%> (-0.4%) ⬇️

... and 1 file with indirect coverage changes

@knaaptime
Copy link
Member

thanks for this!

@robna
Copy link
Contributor Author

robna commented Jul 28, 2023

It was apparent that some functions inside alpha_shapes.py already carry a @jit decorator with explicit nopython=True

I.e.:

@jit(nopython=True)
def r_circumcircle_triangle_single(a, b, c):

@jit(nopython=True)
def r_circumcircle_triangle(a_s, b_s, c_s):

@jit(nopython=True)
def _construct_centers(a, b, radius):

These are not changed by this PR. However, someone more knowledgeable in numba and in this project should review and decide, whether the lines where I now specified nopython=False should better also receive a nopython=True.

voronoi.py imports geopandas (if available) and creates geodataframes, where a `'geometry'` column is manually assigned. This will lead to errors with future versions of geopandas.

```
libpysal/cg/voronoi.py:173: FutureWarning: You are adding a column named 'geometry' to a GeoDataFrame constructed without an active geometry column. Currently, this automatically sets the active geometry column to 'geometry' but in the future that will no longer happen. Instead, either provide geometry to the GeoDataFrame constructor (GeoDataFrame(... geometry=GeoSeries()) or use `set_geometry('geometry')` to explicitly set the active geometry column.
```

Instead, the geodataframe geometry is now specified in the gdf creation via `gpd.GeoDataFrame(geometry = gpd.GeoSeries( ...`
@robna
Copy link
Contributor Author

robna commented Jul 28, 2023

I added one more commit to the PR regarding another deprecation warning:

voronoi.py imports geopandas (if available) and creates geodataframes, where a 'geometry' column is manually assigned. This will lead to errors with future versions of geopandas.

libpysal/cg/voronoi.py:173: FutureWarning: You are adding a column named 'geometry' to a GeoDataFrame constructed without an active geometry column. Currently, this automatically sets the active geometry column to 'geometry' but in the future that will no longer happen. Instead, either provide geometry to the GeoDataFrame constructor (GeoDataFrame(... geometry=GeoSeries()) or use `set_geometry('geometry')` to explicitly set the active geometry column.

Instead, the geometry is now specified in the gdf creation via gpd.GeoDataFrame(geometry = gpd.GeoSeries( ...

Please review,
thank you.

@martinfleis
Copy link
Member

nopython=True is recommended and we should use nopython=False only if the former fails to compile. (source). So I would try to set them all to True and see if CI complains.

@knaaptime
Copy link
Member

knaaptime commented Jul 28, 2023

the default is switching from nopython=False to nopython=True, so these are the ones that raise the warning. In the upcoming versions of numba, the default will switch so the tests will fail for anything that requires python (I played around with this in esda yesterday, and i actually couldn't induce any failures when setting nopython=True, and havent been able to reproduce pysal/esda#240)

@robna
Copy link
Contributor Author

robna commented Jul 29, 2023

actually, both, @jit (without arguments) and @jit(nopython=False) are raising a warning.

NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit...

and

NumbaDeprecationWarning: The keyword argument 'nopython=False' was supplied. From Numba 0.59.0 the default is...

But also for me, no matter what way I set them, there are no severe problems. Just the warnings.

Copy link
Member

@knaaptime knaaptime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit is better than implicit, so we'll want to include nopython=False anyway. I vote to merge

@martinfleis martinfleis changed the title Fixing #526 Explicitly set nopython=False in numba.jit Aug 4, 2023
Copy link
Member

@martinfleis martinfleis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give it a go. We can always revise that if it causes issues (which it should not imho).

@martinfleis martinfleis merged commit e743c48 into pysal:main Aug 4, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NumbaDeprecationWarning: The implicit default value nopython is changing
3 participants