-
Notifications
You must be signed in to change notification settings - Fork 590
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
FEAT: PostGIS support #1787
FEAT: PostGIS support #1787
Conversation
ibis/sql/alchemy.py
Outdated
| @@ -14,6 +14,14 @@ | |||
| from sqlalchemy.ext.compiler import compiles as sa_compiles | |||
| from sqlalchemy.sql.elements import Over as _Over | |||
|
|
|||
| try: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to put all this geoalchemy logic in another submodule, but for now I have it inline with the rest of the sqlalchemy stuff.
ibis/sql/alchemy.py
Outdated
| @@ -881,7 +939,17 @@ def _fetch(self, cursor): | |||
| columns=cursor.proxy.keys(), | |||
| coerce_float=True, | |||
| ) | |||
| return self.schema().apply_to(df) | |||
| df = self.schema().apply_to(df) | |||
| if GEO: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to move this logic elsewhere (possibly even to Schema.apply_to), but for now this is convenient.
|
it is looking pretty good :) it seems there are some pep8 issues ... if you want you can run |
|
Thanks for the tip @xmnlab. At this point a lot of the functionality I'm looking for is in, but it needs a lot of testing. Any tips as to how to go about that? In particular, it would be useful to have a PostGIS-enabled PostgreSQL and a Spatialite-enabled SQLite in CI. |
Codecov Report
@@ Coverage Diff @@
## master #1787 +/- ##
==========================================
- Coverage 87.33% 85.45% -1.88%
==========================================
Files 81 80 -1
Lines 15266 15219 -47
Branches 1965 1956 -9
==========================================
- Hits 13333 13006 -327
- Misses 1567 1860 +293
+ Partials 366 353 -13
|
|
hey @ian-r-rose you can add the tests here: https://github.com/ibis-project/ibis/blob/f6220bb29ea05035ebeb44437c7db36ce0ba8562/ibis/tests/all/test_geospatial.py related to postgis, you can try to change Line 5 in f6220bb
to one docker image from https://wiki.osgeo.org/wiki/DockerImages or https://hub.docker.com/r/geographica/postgis/ (this last one I just find right now) probably you will need to add the the new libs you are using to ci/requirements-dev yaml files related to spatialite extension ... not sure .. maybe you need to add Line 13 in f6220bb
maybe you also will need to change something here: Line 40 in f6220bb
@cpcloud what do you think about this? |
|
Okay, I think this is close-to-ready for some feedback. Tests are mostly passing except for docs (any idea what is going on there?), and most of the functionality I am looking for is in. There are still some tests to write, and some coverage to improve, but querying geospatial data with PostGIS basically works! |
cb9c296
to
b1d8aef
Compare
|
hey @ian-r-rose is this still WIP or is it done for a review? |
|
I think it will need some more test coverage (hence still having WIP), but some review would be helpful at this point. |
|
OK ... I will review it today :) |
|
Thanks! |
.isort.cfg
Outdated
| @@ -1,2 +1,2 @@ | |||
| [settings] | |||
| known_third_party = asv,click,clickhouse_driver,dateutil,google,graphviz,impala,jinja2,kudu,multipledispatch,numpy,pandas,pkg_resources,plumbum,psycopg2,pyarrow,pydata_google_auth,pymapd,pymysql,pytest,pytz,regex,requests,ruamel,setuptools,sphinx_rtd_theme,sqlalchemy,toolz | |||
| known_third_party = asv,click,clickhouse_driver,dateutil,geopandas,google,graphviz,impala,jinja2,kudu,multipledispatch,numpy,pandas,pkg_resources,plumbum,psycopg2,pyarrow,pydata_google_auth,pymapd,pymysql,pytest,pytz,regex,requests,ruamel,setuptools,sphinx_rtd_theme,sqlalchemy,toolz | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also gdal and geoalchemy2 should be added here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was automatically added by the pre-commit hook. Should I edit it manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually not sure .. @cpcloud do you know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is fine. Third-party dependencies get automatically added when they are detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only add gdal and geoalchemy2 if they are imported directly inside of ibis and they are not detected by seed-isort-config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, seed-isort-config doesn't seem to like my manually adding imports here. It is automatically removing them in the pre-commit hook.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think that's probably fine. Does it cause issues elsewhere? If not then I'd say leave as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem to cause any issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And now the file is unchanged. It seems that isort isn't smart enough to see pytest.importorskip or imports in a try/except block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks awesome @ian-r-rose ! I just added small comments.
|
mmm it seems now there is a file with conflict |
|
This is looking pretty close, just a few more review comments and the merge conflict and we should be good to go. |
|
I've made a demonstration gist showing this PR in action: https://gist.github.com/ian-r-rose/255295a5a98ca59259b55aee9a7cfdae It's a little hokey, but shows some non-trivial geospatial operations. |
|
@ian-r-rose your notebook looks great! |
|
Agree with @xmnlab: sweet notebook. |
|
@ian-r-rose As a follow up we might consider adding it to our tutorial notebook collection. |
|
Okay, I think I am happy with this, feature-wise. Ideas for follow-ups:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! thanks @ian-r-rose ! @cpcloud do you think it is done to be merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bravo! LGTM, merging.
|
@ian-r-rose Thanks for all your work on this! |
|
thanks for you hard work @ian-r-rose these new features are awesome! |
|
it seems also it is necessary to add smoke tests for the new ibis expressions: ibis/expr/tests/test_geospatial.py maybe parametrize the tests would be good I will open an issue for that. |
|
Cool. @ian-r-rose Can you open up issues for your bullet points above if you haven't already? |
|
@ian-r-rose just a question, did you add translation for literals for geotypes on postgis? (ex: |
|
No, I don't think so. If you can point me to some examples, I can try to do that in a follow-up. |
|
awesome! this is how geo literals were implemented on mapd: https://github.com/ibis-project/ibis/blob/master/ibis/mapd/operations.py#L390 I think you can add these translations here for postgis: https://github.com/ibis-project/ibis/blob/master/ibis/sql/postgres/compiler.py#L585 |
Follow up to #1787 and #1925 . This adds a number of new operations for the PostGIS backend: * `ST_GeometryType` * `ST_GeometryN` * `ST_IsValid` * `ST_LineLocatePoint` * `ST_LineMerge` * `ST_LineSubstring` * `ST_OrderingEquals` * `ST_Union` The last one requires special attention. That [`ST_Union`](http://postgis.net/docs/ST_Union.html) is available as both a value operation and a column aggregation operation. To avoid a name collision in the ibis APIs, I have named the aggregation variant `unary_union`. This is following the same choice made by [GeoPandas](h ttp://geopandas.org/reference.html#geopandas.GeoSeries.unary_union). Author: Ian Rose <ian.r.rose@gmail.com> Closes #1987 from ian-r-rose/more-postgis-ops and squashes the following commits: aa3de1d [Ian Rose] Work on docstring styles. 379156f [Ian Rose] Export new ops as part of the top-level expr api. dfba5de [Ian Rose] Add ST_Union functionality. 02ba505 [Ian Rose] Add some tests for the new functions. 259a477 [Ian Rose] Work on some additional geospatial operations and their implementation in postgis.
Fixes #1786
This is in an extremely early state, but I wanted to open this for comment now as I'm not likely to get the chance to work much on it for a few days.