siphon
siphon copied to clipboard
Fix deprecation warning from numpy.genfromtxt
So this code:
from datetime import datetime
from siphon.catalog import TDSCatalog
metar_cat_url = ('http://thredds-test.unidata.ucar.edu/thredds/catalog/'
'irma/metar/catalog.xml?dataset=irma/metar/Metar_Station_Data_-_IRMA_fc.cdmr')
catalog = TDSCatalog(metar_cat_url)
metar_dataset = catalog.datasets['Feature Collection']
ncss = metar_dataset.subset()
query = ncss.query()
query.lonlat_box(north=34, south=24, east=-80, west=-90)
query.time(datetime(2017, 9, 10, 12))
query.variables('temperature', 'dewpoint', 'altimeter_setting',
'wind_speed', 'wind_direction', 'sky_coverage')
query.accept('csv')
data = ncss.get_data(query)
produces the warning:
python3.6/site-packages/siphon/ncss.py:433: VisibleDeprecationWarning: Reading unicode strings without specifying the encoding argument is deprecated. Set the encoding, use None for the system default. converters={'date': lambda s: parse_iso_date(s.decode('utf-8'))})
For some reason, our existing tests don't trigger this warning. The warning occurs because numpy 1.14 started being more pedantic about the encoding stuff, and adding an encoding
keyword. We can make things work fine by passing this kwarg with a value of 'utf-8'
, but of course that means we only work on numpy 1.14. Switching to StringIO
instead of BytesIO
does not solve the issue. Options I can think of:
- Bump numpy requirement to 1.14
- Add our own wrapper/helper for
genfromtxt
that is a straight passthru on numpy > 1.14, and drops theencoding
kwarg otherwise - Add a warning filter to swallow the deprecation warning, bump numpy to 1.14 much later.