Closed psychemedia closed 6 years ago
Thanks for reporting this! Fix coming in 15 minutes.
Just fixed this. Thanks again for reporting - much appreciated.
Okay, still an issue:
cart = Cartogram("sample_data/gujarat.json", #input filepath
id_col="AC_NO",
num_x_grid=25, num_y_grid=20 #reduced grid width and height to make map more dense
)
cart.make_hex_geojson("sample_output/gujarat_dense.geojson")
TypeError Traceback (most recent call last)
<ipython-input-8-09891a85aabf> in <module>()
3 num_x_grid=25, num_y_grid=20 #reduced grid width and height to make map more dense
4 )
----> 5 cart.make_hex_geojson("sample_output/gujarat_dense.geojson")
~/Documents/code/github forks/EqualAreaCartogram/eqcart/eqcart.py in make_hex_geojson(self, output_fname)
229 geojson_dict = {"type": "FeatureCollection", "features": features}
230 with open(output_fname, "wb") as f:
--> 231 json.dump(geojson_dict, f)
/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py in dump(obj, fp, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
178 # a debuggability cost
179 for chunk in iterable:
--> 180 fp.write(chunk)
181
182
TypeError: a bytes-like object is required, not 'str'
Drop the b
?
Fixed, thanks
That gives me an error now (sorry, in my testing, I think I got messed up on the version I was running).
I think that with the bytes dropped, line 87 in chorogrid/chorogrid.py
now needs to remove the utf-8 coding?
f.write(svgstring.encode("utf-8"))
-> f.write(svgstring)
I haven't tested with lots of encoded chars (unless your demo files contain them) so I don't know if this is robust. Encodings always catch me out:-(
Thanks again for reporting. Fixed it by handling the write function differently for py2 and py3.
if sys.version_info[0] >= 3:
with open(save_filename, 'w', encoding='utf-8') as f:
f.write(svgstring)
else:
with open(save_filename, 'w') as f:
f.write(svgstring.encode('utf-8'))
Should have done this much earlier. Will also write unit tests for both py2 and 3 so that errors like this do not go unnoticed.
Trying to run the package using Python3 gives errors.
First error:
In Python3,
dict.iteritems
has been replaced bydict.items
.