Skip to content

Commit 6717aa0

Browse files
committed
import msgpack deps only as needed (GH9482)
1 parent f2882b8 commit 6717aa0

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

pandas/io/packers.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,30 @@
6161
import pandas.core.internals as internals
6262

6363
from pandas.msgpack import Unpacker as _Unpacker, Packer as _Packer
64-
import zlib
65-
66-
try:
67-
import blosc
68-
_BLOSC = True
69-
except:
70-
_BLOSC = False
7164

7265
# until we can pass this into our conversion functions,
7366
# this is pretty hacky
7467
compressor = None
68+
_IMPORTS = False
69+
_BLOSC = False
70+
71+
def _importers():
72+
# import things we need
73+
# but make this done on a first use basis
74+
75+
global _IMPORTS
76+
if _IMPORTS:
77+
return
78+
79+
_IMPORTS = True
7580

81+
global _BLOSC
82+
import zlib
83+
try:
84+
import blosc
85+
_BLOSC = True
86+
except:
87+
pass
7688

7789
def to_msgpack(path_or_buf, *args, **kwargs):
7890
"""
@@ -91,6 +103,7 @@ def to_msgpack(path_or_buf, *args, **kwargs):
91103
compress : type of compressor (zlib or blosc), default to None (no
92104
compression)
93105
"""
106+
_importers()
94107
global compressor
95108
compressor = kwargs.pop('compress', None)
96109
append = kwargs.pop('append', None)
@@ -133,6 +146,7 @@ def read_msgpack(path_or_buf, iterator=False, **kwargs):
133146
obj : type of object stored in file
134147
135148
"""
149+
_importers()
136150
path_or_buf, _ = get_filepath_or_buffer(path_or_buf)
137151
if iterator:
138152
return Iterator(path_or_buf)

0 commit comments

Comments
 (0)