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

catch image=None in _retryer() #252

Open
veenstrajelmer opened this issue Aug 30, 2024 · 0 comments
Open

catch image=None in _retryer() #252

veenstrajelmer opened this issue Aug 30, 2024 · 0 comments

Comments

@veenstrajelmer
Copy link
Contributor

veenstrajelmer commented Aug 30, 2024

Follow-up from #247

There are still Nonetype related errors after fixing #248.

When array[0] is None, the code fails on line 682 with an AttributeError:

/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/contextily/plotting.py:134: in add_basemap
    image, extent = bounds2img(
/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/contextily/tile.py:287: in bounds2img
    merged, extent = _merge_tiles(tiles, arrays)
/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/contextily/tile.py:682: in _merge_tiles
    h, w, d = arrays[0].shape
E   AttributeError: 'NoneType' object has no attribute 'shape'

If the first array is valid, but any of the other arrays is None, the issue surfaces a bit lower as a TypeError:

/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/contextily/plotting.py:134: in add_basemap
    image, extent = bounds2img(
/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/contextily/tile.py:287: in bounds2img
    merged, extent = _merge_tiles(tiles, arrays)
/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/contextily/tile.py:692: in _merge_tiles
    img[y * h : (y + 1) * h, x * w : (x + 1) * w, :] = arr
E   TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

I cannot fully grasp what is happening here. I imagined that image=None, and was looking at this part of the code:

with io.BytesIO(request.content) as image_stream:
image = Image.open(image_stream).convert("RGBA")
array = np.asarray(image)
image.close()

So I guess that would lead to this minimal example:

import numpy as np
image = None
array = np.asarray(image)
print(array.shape)

However, this prints () and does not give the error above. @martinfleis do you have an idea how the image variable looks like when this error occurs? Or is my minimal reproduction example faulty?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant