-
Notifications
You must be signed in to change notification settings - Fork 7
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
Allow copy for scalar and nested sequences when converting data to numpy arrays #95
Conversation
test/base_test.py
Outdated
@@ -77,6 +77,27 @@ def test_data_on_array_with_format(self, server, format_arg): | |||
|
|||
assert np.array_equal(retrieved_data, data) | |||
|
|||
# TODO: What should we do for csv, tiff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@t20100 ☝️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷 What does it currently returns? It doesn't sounds useful anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The server encounters an error:
csv
:
File ".../h5grove/h5grove/fastapi_utils.py", line 113, in get_data
h5grove_response = encode(data, format)
File ".../h5grove/h5grove/encoders.py", line 131, in encode
csv_encode(content_array),
File ".../h5grove/h5grove/encoders.py", line 58, in csv_encode
np.savetxt(buffer, data, delimiter=",")
File ".../h5grove/lib/python3.10/site-packages/numpy/lib/_npyio_impl.py", line 1573, in savetxt
raise ValueError(
ValueError: Expected 1D or 2D array, got 0D array instead
tiff
:
File ".../h5grove/h5grove/encoders.py", line 149, in encode
tiff_encode(content_array),
File ".../h5grove/h5grove/encoders.py", line 78, in tiff_encode
tifffile.imwrite(buffer, data, photometric="minisblack")
File ".../h5grove/lib/python3.10/site-packages/tifffile/tifffile.py", line 966, in imwrite
result = tif.write(data, shape, dtype, **kwargs)
File ".../h5grove/lib/python3.10/site-packages/tifffile/tifffile.py", line 2020, in write
raise RuntimeError(
RuntimeError: length of storedshape 4 not in (5, 6)
In both cases, the server returns an HTTP Error 500 to the user. I wondered if we could not make it more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered if we could not make it more explicit.
+1
What would be the best error code? 415 Unsupported Media Type ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just 400 - Bad Request, I think. Those format
values just aren't supported by the /data/
endpoint for scalar datasets. Clients are expected to know about this (ideally from h5grove's documentation) and not try to make the request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already stuff put in place to raise 422 Unprocessable Content for some encodings if the data is not numeric:
Line 124 in 53d7d0f
if not is_numeric_data(content_array): |
Line 297 in 53d7d0f
except QueryArgumentError as e: |
We could reuse it to raise a 422 error in case of unsupported encoding for scalars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
Fix #94
Also brings support for Numpy v2. See the discussion at #94 for more info: