-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bugs in json-encoding of documents (#713)
* Add explicit support for bbox marshalling * Make sure we encode bytes as base64 so they're always encodable as json * Test this using materialize on our actual data.
- Loading branch information
1 parent
88c180f
commit 0a3ed08
Showing
7 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+556 KB
.../tests/resources/data/materialize/json_writer/3fe9913e-60e2-11ef-90e5-e40d36f1e1ae.pickle
Binary file not shown.
Empty file.
Binary file added
BIN
+153 Bytes
...sts/resources/data/materialize/json_writer/md-9e6e68ee-ad8e-4e39-a2e1-7ef5befc588c.pickle
Binary file not shown.
33 changes: 33 additions & 0 deletions
33
lib/sycamore/sycamore/tests/unit/connectors/file/test_file_writer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sycamore | ||
from sycamore.materialize import MaterializeSourceMode | ||
from sycamore.tests.config import TEST_DIR | ||
from sycamore.connectors.file.file_writer import document_to_json_bytes | ||
|
||
# To re-generate the input file, change the False to True, and in the root directory, run | ||
# poetry run python lib/sycamore/sycamore/tests/unit/connectors/file/test_file_writer.py | ||
if False: | ||
from sycamore.transforms.partition import ArynPartitioner | ||
|
||
( | ||
sycamore.init() | ||
.read.binary(paths="./lib/sycamore/sycamore/tests/resources/data/pdfs/Ray_page11.pdf", binary_format="pdf") | ||
.partition(ArynPartitioner(extract_images=True, use_partitioning_service=False, use_cache=False)) | ||
.materialize( | ||
path="./lib/sycamore/sycamore/tests/resources/data/materialize/json_writer", | ||
source_mode=MaterializeSourceMode.IF_PRESENT, | ||
) | ||
.execute() | ||
) | ||
|
||
|
||
def test_json_bytes_with_bbox_image(): | ||
docs = ( | ||
sycamore.init(exec_mode=sycamore.ExecMode.LOCAL) | ||
.read.materialize(path=TEST_DIR / "resources/data/materialize/json_writer") | ||
.take_all() | ||
) | ||
# TODO: once we support writers in local mode, switch this to be | ||
# .write.json(tmpdir) | ||
# running as part of ray, it's too slow | ||
for d in docs: | ||
_ = document_to_json_bytes(d) |