Skip to content

Commit

Permalink
numba bool fun (#324)
Browse files Browse the repository at this point in the history
* numba bool fun

* simpler
  • Loading branch information
martindurant committed Apr 8, 2018
1 parent d94ea63 commit fbb024e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions fastparquet/benchmarks/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def time_column():
'y': r / np.random.randint(1, 1000, size=n),
'z': np.random.randint(0, 127, size=n,
dtype=np.uint8)})
d['b'] = r > 0

for col in d.columns:
df = d[[col]]
Expand Down
17 changes: 15 additions & 2 deletions fastparquet/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,23 @@
from .util import byte_buffer


@numba.njit(nogil=True)
def unpack_boolean(data, out):
for i in range(len(data)):
d = data[i]
for j in range(8):
out[i * 8 + j] = d & 1
d >>= 1


def read_plain_boolean(raw_bytes, count):
"""Read `count` booleans using the plain encoding."""
return np.unpackbits(np.frombuffer(raw_bytes, dtype=np.uint8)).reshape(
(-1, 8))[:, ::-1].ravel().astype(bool)[:count]
data = np.frombuffer(raw_bytes, dtype='uint8')
padded = len(raw_bytes) * 8
out = np.empty(padded, dtype=bool)
unpack_boolean(data, out)
return out[:count]


DECODE_TYPEMAP = {
parquet_thrift.Type.INT32: np.int32,
Expand Down

0 comments on commit fbb024e

Please sign in to comment.