Skip to content

Commit

Permalink
Merge pull request #598 from voxel51/release/v0.10.0
Browse files Browse the repository at this point in the history
Release/v0.10.0
  • Loading branch information
findtopher authored May 17, 2023
2 parents 47b9eb4 + 4a01595 commit f033bb8
Show file tree
Hide file tree
Showing 9 changed files with 1,033 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
publish:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
steps:
- name: Clone ETA
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
**/*.md5
*.log
**/*.log
.idea

__pycache__
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ infrastructure.**
ETA is very portable:

- Installable on Mac or Linux
- Supports Python 2.7 and Python 3.6 or later
- Supports Python 3.6 or later
- Supports TensorFlow 1.X and 2.X
- Supports OpenCV 2.4+ and OpenCV 3.0+
- Supports CPU-only and GPU-enabled installations
Expand Down
29 changes: 18 additions & 11 deletions eta/core/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from uuid import uuid4
import zlib

import ndjson
import jsonlines
import numpy as np

import eta.core.utils as etau
Expand Down Expand Up @@ -134,16 +134,16 @@ def read_ndjson(path):
Returns:
a list of JSON dicts
"""
with open(path, "rt") as f:
return ndjson.load(f)
with jsonlines.open(path) as r:
return list(r.iter(skip_empty=True))


def load_ndjson(path_or_str):
"""Loads NDJSON from the input argument.
The input argument can be any of the following:
(a) the path to a NDJSON file on disk
(b) a string that can be directly parsed via `ndjson.loads`
(b) an NDJSON string or bytes
Args:
path_or_str: the NDJSON path or string
Expand All @@ -162,10 +162,13 @@ def load_ndjson(path_or_str):

def _load_ndjson(str_or_bytes):
try:
return ndjson.loads(str_or_bytes)
except TypeError:
# Must be a Python version for which ndjson.loads() cannot handle bytes
return ndjson.loads(str_or_bytes.decode("utf-8"))
ndjson_str = str_or_bytes.decode("utf-8")
except AttributeError:
ndjson_str = str_or_bytes

with io.StringIO(ndjson_str) as f:
with jsonlines.Reader(f) as r:
return list(r.iter(skip_empty=True))


def write_ndjson(obj, path, append=False):
Expand All @@ -185,7 +188,11 @@ def write_ndjson(obj, path, append=False):

mode = "at" if append else "wt"
with open(path, mode) as f:
f.write(prefix + ndjson.dumps(obj))
if prefix:
f.write(prefix)

with jsonlines.Writer(f) as w:
w.write_all(obj)


def json_to_str(obj, pretty_print=True):
Expand Down Expand Up @@ -1142,8 +1149,8 @@ def add_by_path(self, path):
def add_iterable(self, elements):
"""Adds the elements in the given iterable to the Big iterable.
Args:
elements: an iterable of elements
Args:
elements: an iterable of elements
"""
raise NotImplementedError("subclasses must implement add_iterable()")

Expand Down
Loading

0 comments on commit f033bb8

Please sign in to comment.