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

drop last bits of python 2 #659

Merged
merged 2 commits into from
Feb 26, 2020
Merged

Conversation

ocefpaf
Copy link
Contributor

@ocefpaf ocefpaf commented Feb 20, 2020

This PR is a bit more complicated than it looks and you may delay the merge until OWSLib is ready to drop Python 3.5 support too.

The reason is that, with this PR, some responses are no longer converted to str. The main advantage is that everything is bytes in a way we expected from Python 3. The downside is that Python 3.5 json module cannot handle bytes, that started in 3.6, and some users may still expect str rather than bytes in their workflow. (See the docs test where I had to add the b"" as an example of that.)

@cehbrecht cehbrecht self-requested a review February 20, 2020 16:15
@cehbrecht cehbrecht added this to the 0.20.0 milestone Feb 20, 2020
@cehbrecht
Copy link
Contributor

@tomkralidis I'm ok with dropping Python 3.5. What do you think?

@cehbrecht cehbrecht merged commit 79f9430 into geopython:master Feb 26, 2020
@cehbrecht
Copy link
Contributor

@ocefpaf merged. Thanks :)

@ocefpaf ocefpaf deleted the last_bits_of_py2 branch February 26, 2020 13:19
tlvu added a commit to Ouranosinc/pavics-sdi that referenced this pull request Apr 28, 2020
…tead of string

New owslib 0.19.2 (we had 0.19.1 before) deprecated python 2 so
responses are now bytes instead of string.  See PR
geopython/OWSLib#659 or commit
geopython/OWSLib@79f9430.

Fix the following Jenkins error:

```
12:25:22  ______ pavics-sdi-master/docs/source/notebooks/WFS_example.ipynb::Cell 3 _______
12:25:22  Notebook cell execution failed
12:25:22  Cell 3: Cell execution caused an exception
12:25:22
12:25:22  Input:
12:25:22  layer_id = 'public:canada_admin_boundaries'
12:25:22  meta = wfs.contents[layer_id]
12:25:22  print(meta.title)
12:25:22
12:25:22  # Get the actual data
12:25:22  data = wfs.getfeature(typename='public:canada_admin_boundaries', bbox=(-74.5, 45.2, -73, 46), outputFormat='JSON')
12:25:22
12:25:22  # Write to file
12:25:22  fn = 'output.geojson'
12:25:22  with open(fn, 'w', encoding="utf-8") as fh:
12:25:22      fh.write(data.read())
12:25:22
12:25:22  Traceback:
12:25:22
12:25:22  ---------------------------------------------------------------------------
12:25:22  TypeError                                 Traceback (most recent call last)
12:25:22  <ipython-input-4-9fde860af399> in <module>
12:25:22        9 fn = 'output.geojson'
12:25:22       10 with open(fn, 'w', encoding="utf-8") as fh:
12:25:22  ---> 11     fh.write(data.read())
12:25:22
12:25:22  TypeError: write() argument must be str, not bytes
12:25:22
12:25:22  ______ pavics-sdi-master/docs/source/notebooks/WFS_example.ipynb::Cell 4 _______
12:25:22  Notebook cell execution failed
12:25:22  Cell 4: Cell execution caused an exception
12:25:22
12:25:22  Input:
12:25:22  layers = gpd.read_file(fn)
12:25:22  layers.plot()
12:25:22
12:25:22  Traceback:
12:25:22
12:25:22  ---------------------------------------------------------------------------
12:25:22  CPLE_OpenFailedError                      Traceback (most recent call last)
12:25:22  fiona/_shim.pyx in fiona._shim.gdal_open_vector()
12:25:22
12:25:22  fiona/_err.pyx in fiona._err.exc_wrap_pointer()
12:25:22
12:25:22  CPLE_OpenFailedError: 'output.geojson' not recognized as a supported file format.
12:25:22
12:25:22  During handling of the above exception, another exception occurred:
12:25:22
12:25:22  DriverError                               Traceback (most recent call last)
12:25:22  <ipython-input-5-13d953acb915> in <module>
12:25:22  ----> 1 layers = gpd.read_file(fn)
12:25:22        2 layers.plot()
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/geopandas/io/file.py in read_file(filename, bbox, mask, rows, **kwargs)
12:25:22       87
12:25:22       88     with fiona_env():
12:25:22  ---> 89         with reader(path_or_bytes, **kwargs) as features:
12:25:22       90
12:25:22       91             # In a future Fiona release the crs attribute of features will
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/fiona/env.py in wrapper(*args, **kwargs)
12:25:22      396     def wrapper(*args, **kwargs):
12:25:22      397         if local._env:
12:25:22  --> 398             return f(*args, **kwargs)
12:25:22      399         else:
12:25:22      400             if isinstance(args[0], str):
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/fiona/__init__.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
12:25:22      252         if mode in ('a', 'r'):
12:25:22      253             c = Collection(path, mode, driver=driver, encoding=encoding,
12:25:22  --> 254                            layer=layer, enabled_drivers=enabled_drivers, **kwargs)
12:25:22      255         elif mode == 'w':
12:25:22      256             if schema:
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
12:25:22      152             if self.mode == 'r':
12:25:22      153                 self.session = Session()
12:25:22  --> 154                 self.session.start(self, **kwargs)
12:25:22      155             elif self.mode in ('a', 'w'):
12:25:22      156                 self.session = WritingSession()
12:25:22
12:25:22  fiona/ogrext.pyx in fiona.ogrext.Session.start()
12:25:22
12:25:22  fiona/_shim.pyx in fiona._shim.gdal_open_vector()
12:25:22
12:25:22  DriverError: 'output.geojson' not recognized as a supported file format.
```
tlvu added a commit to Ouranosinc/pavics-sdi that referenced this pull request Apr 28, 2020
…tead of string

New owslib 0.19.2 (we had 0.19.1 before) dropped python 2 so
responses are now bytes instead of string.  See PR
geopython/OWSLib#659 or commit
geopython/OWSLib@79f9430.

Fix the following Jenkins error:

```
12:25:22  ______ pavics-sdi-master/docs/source/notebooks/WFS_example.ipynb::Cell 3 _______
12:25:22  Notebook cell execution failed
12:25:22  Cell 3: Cell execution caused an exception
12:25:22
12:25:22  Input:
12:25:22  layer_id = 'public:canada_admin_boundaries'
12:25:22  meta = wfs.contents[layer_id]
12:25:22  print(meta.title)
12:25:22
12:25:22  # Get the actual data
12:25:22  data = wfs.getfeature(typename='public:canada_admin_boundaries', bbox=(-74.5, 45.2, -73, 46), outputFormat='JSON')
12:25:22
12:25:22  # Write to file
12:25:22  fn = 'output.geojson'
12:25:22  with open(fn, 'w', encoding="utf-8") as fh:
12:25:22      fh.write(data.read())
12:25:22
12:25:22  Traceback:
12:25:22
12:25:22  ---------------------------------------------------------------------------
12:25:22  TypeError                                 Traceback (most recent call last)
12:25:22  <ipython-input-4-9fde860af399> in <module>
12:25:22        9 fn = 'output.geojson'
12:25:22       10 with open(fn, 'w', encoding="utf-8") as fh:
12:25:22  ---> 11     fh.write(data.read())
12:25:22
12:25:22  TypeError: write() argument must be str, not bytes
12:25:22
12:25:22  ______ pavics-sdi-master/docs/source/notebooks/WFS_example.ipynb::Cell 4 _______
12:25:22  Notebook cell execution failed
12:25:22  Cell 4: Cell execution caused an exception
12:25:22
12:25:22  Input:
12:25:22  layers = gpd.read_file(fn)
12:25:22  layers.plot()
12:25:22
12:25:22  Traceback:
12:25:22
12:25:22  ---------------------------------------------------------------------------
12:25:22  CPLE_OpenFailedError                      Traceback (most recent call last)
12:25:22  fiona/_shim.pyx in fiona._shim.gdal_open_vector()
12:25:22
12:25:22  fiona/_err.pyx in fiona._err.exc_wrap_pointer()
12:25:22
12:25:22  CPLE_OpenFailedError: 'output.geojson' not recognized as a supported file format.
12:25:22
12:25:22  During handling of the above exception, another exception occurred:
12:25:22
12:25:22  DriverError                               Traceback (most recent call last)
12:25:22  <ipython-input-5-13d953acb915> in <module>
12:25:22  ----> 1 layers = gpd.read_file(fn)
12:25:22        2 layers.plot()
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/geopandas/io/file.py in read_file(filename, bbox, mask, rows, **kwargs)
12:25:22       87
12:25:22       88     with fiona_env():
12:25:22  ---> 89         with reader(path_or_bytes, **kwargs) as features:
12:25:22       90
12:25:22       91             # In a future Fiona release the crs attribute of features will
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/fiona/env.py in wrapper(*args, **kwargs)
12:25:22      396     def wrapper(*args, **kwargs):
12:25:22      397         if local._env:
12:25:22  --> 398             return f(*args, **kwargs)
12:25:22      399         else:
12:25:22      400             if isinstance(args[0], str):
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/fiona/__init__.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
12:25:22      252         if mode in ('a', 'r'):
12:25:22      253             c = Collection(path, mode, driver=driver, encoding=encoding,
12:25:22  --> 254                            layer=layer, enabled_drivers=enabled_drivers, **kwargs)
12:25:22      255         elif mode == 'w':
12:25:22      256             if schema:
12:25:22
12:25:22  /usr/local/envs/birdy/lib/python3.7/site-packages/fiona/collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
12:25:22      152             if self.mode == 'r':
12:25:22      153                 self.session = Session()
12:25:22  --> 154                 self.session.start(self, **kwargs)
12:25:22      155             elif self.mode in ('a', 'w'):
12:25:22      156                 self.session = WritingSession()
12:25:22
12:25:22  fiona/ogrext.pyx in fiona.ogrext.Session.start()
12:25:22
12:25:22  fiona/_shim.pyx in fiona._shim.gdal_open_vector()
12:25:22
12:25:22  DriverError: 'output.geojson' not recognized as a supported file format.
```
tlvu added a commit to Ouranosinc/pavics-sdi that referenced this pull request Apr 29, 2020
…-jupyter-env


Update notebooks to match new Jupyter env.

To match new Jupyter env in PR Ouranosinc/PAVICS-e2e-workflow-tests#43.

New owslib 0.19.2 (we had 0.19.1 before) dropped the remaining of python 2 support so responses are now bytes instead of string.  See PR geopython/OWSLib#659 or commit geopython/OWSLib@79f9430.  I wouldn't expect a patch version release to drop python 2 support !

New xarray 0.15.1 default to html style output that allows collapsing/expanding data, see PR pydata/xarray#3812 or commit pydata/xarray@b155853.

![2020-04-28-134427_536x549_scrot](https://user-images.githubusercontent.com/11966697/80519794-89c80000-8956-11ea-8f0d-b95360b2d46c.png)
    
Unfortunately had to force the old text style since the html style has randomness that breaks automated testing of the notebooks using nbval pytest plugin.

Finally a passing Jenkins run: http://jenkins.ouranos.ca/job/PAVICS-e2e-workflow-tests/job/new-docker-release-for-xclim/5/console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants