Skip to content

Commit 37a744d

Browse files
authored
Merge pull request pandas-dev#794 from shashank88/no_bson
Add a config option to skip bson encoding in pickle store
2 parents 9fe59ef + 2a41b3e commit 37a744d

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

arctic/_config.py

+7
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,10 @@ class FwPointersCfg(Enum):
103103
# Flag used for indicating caching levels. For now just for list_libraries.
104104
# -------------------------------
105105
ENABLE_CACHE = not bool(os.environ.get('ARCTIC_DISABLE_CACHE'))
106+
107+
# -------------------------------
108+
# Currently we try to bson encode if the data is less than a given size and store it in
109+
# the version collection, but pickling might be preferable if we have characters that don't
110+
# play well with the bson encoder or if you always want your data in the data collection.
111+
# -------------------------------
112+
SKIP_BSON_ENCODE_PICKLE_STORE = bool(os.environ.get('SKIP_BSON_ENCODE_PICKLE_STORE'))

arctic/store/_pickle_store.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from ._version_store_utils import checksum, pickle_compat_load, version_base_or_id
1212
from .._compression import decompress, compress_array
1313
from ..exceptions import UnsupportedPickleStoreVersion
14+
from .._config import SKIP_BSON_ENCODE_PICKLE_STORE
15+
1416

1517
# new versions of chunked pickled objects MUST begin with __chunked__
1618
_MAGIC_CHUNKED = '__chunked__'
@@ -75,15 +77,19 @@ def read(self, mongoose_lib, version, symbol, **kwargs):
7577
def read_options():
7678
return []
7779

78-
def write(self, arctic_lib, version, symbol, item, previous_version):
79-
try:
80-
# If it's encodeable, then ship it
81-
b = bson.BSON.encode({'data': item})
82-
if len(b) < _MAX_BSON_ENCODE:
83-
version['data'] = item
84-
return
85-
except InvalidDocument:
86-
pass
80+
def write(self, arctic_lib, version, symbol, item, _previous_version):
81+
# Currently we try to bson encode if the data is less than a given size and store it in
82+
# the version collection, but pickling might be preferable if we have characters that don't
83+
# play well with the bson encoder or if you always want your data in the data collection.
84+
if not SKIP_BSON_ENCODE_PICKLE_STORE:
85+
try:
86+
# If it's encodeable, then ship it
87+
b = bson.BSON.encode({'data': item})
88+
if len(b) < _MAX_BSON_ENCODE:
89+
version['data'] = item
90+
return
91+
except InvalidDocument:
92+
pass
8793

8894
# Pickle, chunk and store the data
8995
collection = arctic_lib.get_top_level_collection()

0 commit comments

Comments
 (0)