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

"path too long for Windows" when calling ak.from_json with a long json string on Windows #1084

Closed
nikoladze opened this issue Sep 8, 2021 · 2 comments · Fixed by #1085
Closed
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged

Comments

@nikoladze
Copy link
Contributor

Version of Awkward Array

not sure

Description and code to reproduce

Discovered by a student in a course (who was working on Windows). We were going through the bikeroutes example:

import awkward as ak
import urllib
url = "https://raw.githubusercontent.com/Chicago/osd-bike-routes/master/data/Bikeroutes.geojson"
bikeroutes_json = urllib.request.urlopen(url).read()
bikeroutes = ak.from_json(bikeroutes_json)

Gave him the following error:

ValueError Traceback (most recent call last)
<ipython-input-25-171b38169686> in <module>
----> 1 bikeroutes = ak.from_json(bikeroutes_json)

~\Anaconda3\lib\site-packages\awkward\operations\convert.py in from_json(source, nan_string, infinity_string, minus_infinity_string, complex_record_fields, highlevel, behavior, initial, resize, buffersize)
1054 is_path, source = ak._util.regularize_path(source)
1055
-> 1056 if os.path.isfile(source):
1057 layout = ak._ext.fromjsonfile(
1058 source,

~\Anaconda3\lib\genericpath.py in isfile(path)
28 """Test whether a path is a regular file"""
29 try:
---> 30 st = os.stat(path)
31 except OSError:
32 return False

ValueError: stat: path too long for Windows

unfortunately i currently have no windows Installation available to reproduce it

@nikoladze nikoladze added the bug (unverified) The problem described would be a bug, but needs to be triaged label Sep 8, 2021
@agoose77
Copy link
Collaborator

agoose77 commented Sep 8, 2021

I don't have a Windows to hand to confirm this, but it looks very plausible — Windows has a 260 char path limit IIRC, and we check whether source is a path first.

@jpivarski
Copy link
Member

If the path is too long, then it can't be a real file, so this should have an easy fix: we can catch the ValueError and go into the mode of assuming that the string is JSON.

For the bike routes example, ak.from_iter(py_bikeroutes) is an alternative to ak.from_json(js_bikeroutes).

@jpivarski jpivarski linked a pull request Sep 8, 2021 that will close this issue
agoose77 added a commit that referenced this issue Sep 9, 2021
agoose77 added a commit that referenced this issue Sep 9, 2021
jpivarski added a commit that referenced this issue Sep 27, 2021
* Fix: add utility to check whether a string is a filepath

* Fix: anticipate ValueError for Window isfile

* Test: add test for #1084

* Test: use SHA in url

* Fix: fix test using pytest.skip

* Fix: revert accidental testing changes

* Don't attempt to test in Python 2.7 (urllib names were different).

* Python 2.7 error already happened at import-time.

Co-authored-by: Jim Pivarski <jpivarski@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unverified) The problem described would be a bug, but needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants