Skip to content

Commit 9962aaa

Browse files
committed
Added DataFrame.display function for passing parameters to rendering normally called by IPython display.
Upgraded suite of Python dependencies.
1 parent 91fe328 commit 9962aaa

File tree

8 files changed

+67
-39
lines changed

8 files changed

+67
-39
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ orbs:
4242
steps:
4343
- run:
4444
name: Install requirements
45-
command: python -m pip install --progress-bar=off --user -r pyrasterframes/src/main/python/requirements.txt
45+
command: conda install -c conda-forge --file pyrasterframes/src/main/python/requirements-condaforge.txt
46+
4647

4748
rasterframes:
4849
commands:

docs/src/main/paradox/release-notes.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
### 0.9.1
66

77
* Upgraded to Spark 2.4.7
8+
* Added `pyspark.sql.DataFrame.display(num_rows, truncate)` extension method when `rf_ipython` is imported.
89
* Added `method_name` parameter to the `rf_resample` method.
910
* __BREAKING__: In SQL, the function `rf_resample` now takes 3 arguments. You can use `rf_resample_nearest` with two arguments or refactor to `rf_resample(t, v, "nearest")`.
1011
* Added resample method parameter to SQL and Python APIs. @ref:[See updated docs](raster-join.md).
12+
* Upgraded many of the pyrasterframes dependencies, including:
13+
`descartes`, `fiona`, `folium`, `geopandas`, `matplotlib`, `numpy`, `pandas`, `rasterio`, `shapely`
1114

1215

1316
### 0.9.0

pyrasterframes/src/main/python/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ Issue tracking is through [github](https://github.com/locationtech/rasterframes/
3838

3939
Community contributions are always welcome. To get started, please review our [contribution guidelines](https://github.com/locationtech/rasterframes/blob/develop/CONTRIBUTING.md), [code of conduct](https://github.com/locationtech/rasterframes/blob/develop/CODE_OF_CONDUCT.md), and [developer's guide](../../../README.md). Reach out to us on [gitter][gitter] so the community can help you get started!
4040

41+
## Development environment setup
4142

43+
For best results, we suggest using `conda` and the `conda-forge` channel to install the compiled dependencies before installing the packages in `setup.py`. Assuming you're in the same directory as this file:
44+
45+
conda create -n rasterframes python==3.7
46+
conda install --file ./requirements-condaforge.txt
47+
48+
Then you can install the source dependencies:
49+
50+
pip install -e .
4251

4352
[gitter]: https://gitter.im/locationtech/rasterframes

pyrasterframes/src/main/python/pyrasterframes/rf_ipython.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def _folium_map_formatter(map) -> str:
226226

227227
try:
228228
from IPython import get_ipython
229-
from IPython.display import display_png, display_markdown, display
229+
from IPython.display import display_png, display_markdown, display_html, display
230230
# modifications to currently running ipython session, if we are in one; these enable nicer visualization for Pandas
231231
if get_ipython() is not None:
232232
import pandas
@@ -259,9 +259,12 @@ def _folium_map_formatter(map) -> str:
259259
pyspark.sql.DataFrame.showHTML = spark_df_to_html
260260
Tile.show = plot_tile
261261

262-
# This is a trick we may have to introduce above.
263-
# from IPython.display import display_html
264-
# display_html(rf.showHTML(truncate=True), raw=True)
262+
def _display(df: pyspark.sql.DataFrame, num_rows: int = 5, truncate: bool = False) -> ():
263+
# noinspection PyTypeChecker
264+
display_html(spark_df_to_html(df, num_rows, truncate), raw=True)
265+
266+
pyspark.sql.DataFrame.display = _display
267+
265268

266269
except ImportError as e:
267270
pass
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These packages should be installed from conda-forge, given their complex binary components.
2+
gdal==2.4.4
3+
rasterio[s3]
4+
rtree

pyrasterframes/src/main/python/requirements.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

pyrasterframes/src/main/python/setup.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,28 +136,28 @@ def dest_file(self, src_file):
136136
boto3 = 'boto3'
137137
deprecation = 'deprecation'
138138
descartes = 'descartes'
139-
fiona = 'fiona==1.8.6'
139+
fiona = 'fiona'
140140
folium = 'folium'
141141
gdal = 'gdal==2.4.4'
142-
geopandas = 'geopandas>=0.7'
143-
ipykernel = 'ipykernel==4.8.0'
144-
ipython = 'ipython==6.2.1'
142+
geopandas = 'geopandas'
143+
ipykernel = 'ipykernel'
144+
ipython = 'ipython'
145145
jupyter_client = 'jupyter-client<6.0' # v6 breaks pweave
146-
matplotlib = 'matplotlib'
147146
nbclient = 'nbclient==0.1.0' # compatible with our pweave => jupyter_client restrictions
148-
nbconvert = 'nbconvert==5.5.0'
149-
numpy = 'numpy>=1.17.3,<2.0'
150-
pandas = 'pandas>=0.25.3,<1.0'
147+
matplotlib = 'matplotlib'
148+
nbconvert = 'nbconvert'
149+
numpy = 'numpy'
150+
pandas = 'pandas'
151151
pweave = 'pweave==0.30.3'
152152
pypandoc = 'pypandoc'
153153
pyspark = 'pyspark==2.4.7'
154-
pytest = 'pytest>=4.0.0,<5.0.0'
154+
pytest = 'pytest'
155155
pytest_runner = 'pytest-runner'
156156
pytz = 'pytz'
157-
rasterio = 'rasterio>=1.0.0'
157+
rasterio = 'rasterio'
158158
requests = 'requests'
159-
setuptools = 'setuptools>=45.2.0'
160-
shapely = 'Shapely>=1.6.0'
159+
setuptools = 'setuptools'
160+
shapely = 'Shapely'
161161
tabulate = 'tabulate'
162162
tqdm = 'tqdm'
163163
utm = 'utm'

pyrasterframes/src/main/python/tests/IpythonTests.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@
2222

2323

2424
import pyrasterframes
25-
import pyrasterframes.rf_ipython
26-
from pyrasterframes.rasterfunctions import *
2725
from pyrasterframes.rf_types import *
2826

29-
from IPython.display import display_markdown
30-
from IPython.display import display_html
31-
3227
import numpy as np
3328

3429
from py4j.protocol import Py4JJavaError
30+
from IPython.testing import globalipapp
3531
from . import TestEnvironment
3632

3733
class IpythonTests(TestEnvironment):
3834

39-
def setUp(self):
40-
self.create_layer()
35+
@classmethod
36+
def setUpClass(cls):
37+
super().setUpClass()
38+
globalipapp.start_ipython()
39+
40+
@classmethod
41+
def tearDownClass(cls) -> None:
42+
globalipapp.get_ipython().atexit_operations()
43+
4144

4245
@skip("Pending fix for issue #458")
4346
def test_all_nodata_tile(self):
@@ -60,3 +63,23 @@ def test_all_nodata_tile(self):
6063
self.fail("test_all_nodata_tile failed with Py4JJavaError")
6164
except:
6265
self.fail("um")
66+
67+
def test_display_extension(self):
68+
# noinspection PyUnresolvedReferences
69+
import pyrasterframes.rf_ipython
70+
71+
self.create_layer()
72+
ip = globalipapp.get_ipython()
73+
74+
num_rows = 2
75+
row_count = 0
76+
77+
def counter(data, _):
78+
nonlocal row_count
79+
row_count = data.count('<tr>')
80+
ip.mime_renderers['text/html'] = counter
81+
82+
self.df.display(num_rows=num_rows)
83+
84+
# Plus one for the header row.
85+
self.assertIs(row_count, num_rows+1)

0 commit comments

Comments
 (0)