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

fixes for numpy2 #886

Merged
merged 3 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
- name: pip-install
shell: bash -l {0}
run: |
pip install Cython
pip install 'Cython<3'
pip install hypothesis
pip install pytest-localserver pytest-xdist pytest-asyncio
pip install -e . --no-deps # Install fastparquet
Expand Down
22 changes: 13 additions & 9 deletions fastparquet/test/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import pytest
from packaging.version import Version

from fastparquet.json import (
JsonCodecError,
Expand All @@ -25,15 +26,15 @@ def _clear_cache():


@pytest.mark.parametrize(
"data",
"data,has_float64",
[
None,
[1, 1, 2, 3, 5],
[1.23, -3.45],
[np.float64(0.12), np.float64(4.56)],
[[1, 2, 4], ["x", "y", "z"]],
{"k1": "value", "k2": "à/è", "k3": 3},
{"k1": [1, 2, 3], "k2": [4.1, 5.2, 6.3]},
(None, False),
([1, 1, 2, 3, 5], False),
([1.23, -3.45], False),
([np.float64(0.12), np.float64(4.56)], True),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what to do about this but rapidjson.dumps produces invalid json for:

>>> rapidjson.dumps(np.float64(0.1))
'np.float64(0.1)'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't suppose there's a good reason rapidjson should know what to do with that

([[1, 2, 4], ["x", "y", "z"]], False),
({"k1": "value", "k2": "à/è", "k3": 3}, False),
({"k1": [1, 2, 3], "k2": [4.1, 5.2, 6.3]}, False),
],
)
@pytest.mark.parametrize(
Expand All @@ -44,7 +45,10 @@ def _clear_cache():
"decoder_module, decoder_class",
list(_codec_classes.items()),
)
def test_engine(encoder_module, encoder_class, decoder_module, decoder_class, data):
def test_engine(encoder_module, encoder_class, decoder_module, decoder_class, data, has_float64):
if encoder_module == "rapidjson" and has_float64 and Version(np.__version__).major >= 2:
pytest.skip(reason="rapidjson cannot json dump np.float64 on numpy 2")

pytest.importorskip(encoder_module)
pytest.importorskip(decoder_module)

Expand Down
4 changes: 2 additions & 2 deletions fastparquet/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def convert(data, se):
elif type == parquet_thrift.Type.BOOLEAN:
# TODO: with our own bitpack writer, no need to copy for
# the padding
padded = np.lib.pad(data.values, (0, 8 - (len(data) % 8)),
padded = np.pad(data.values, (0, 8 - (len(data) % 8)),
'constant', constant_values=(0, 0))
out = np.packbits(padded.reshape(-1, 8)[:, ::-1].ravel())
elif dtype.name in typemap:
Expand All @@ -265,7 +265,7 @@ def convert(data, se):
elif type == parquet_thrift.Type.BOOLEAN:
# TODO: with our own bitpack writer, no need to copy for
# the padding
padded = np.lib.pad(data.values, (0, 8 - (len(data) % 8)),
padded = np.pad(data.values, (0, 8 - (len(data) % 8)),
'constant', constant_values=(0, 0))
out = np.packbits(padded.reshape(-1, 8)[:, ::-1].ravel())
else:
Expand Down
Loading