18
18
from msgpack import Packer as _Packer , Unpacker as _Unpacker , \
19
19
unpack as _unpack , unpackb as _unpackb
20
20
21
- def encode (obj , chain = None , copyless = False ):
21
+ def encode (obj , chain = None ):
22
22
"""
23
23
Data encoder for serializing numpy data types.
24
24
"""
@@ -32,27 +32,15 @@ def encode(obj, chain=None, copyless=False):
32
32
else :
33
33
kind = b''
34
34
descr = obj .dtype .str
35
- if copyless :
36
- return {b'nd' : True ,
37
- b'type' : descr ,
38
- b'kind' : kind ,
39
- b'shape' : obj .shape ,
40
- b'data' : obj .data }
41
- else :
42
- return {b'nd' : True ,
43
- b'type' : descr ,
44
- b'kind' : kind ,
45
- b'shape' : obj .shape ,
46
- b'data' : obj .tobytes ()}
35
+ return {b'nd' : True ,
36
+ b'type' : descr ,
37
+ b'kind' : kind ,
38
+ b'shape' : obj .shape ,
39
+ b'data' : obj .data }
47
40
elif isinstance (obj , (np .bool_ , np .number )):
48
- if copyless :
49
- return {b'nd' : False ,
50
- b'type' : obj .dtype .str ,
51
- b'data' : obj .tobytes ()}
52
- else :
53
- return {b'nd' : False ,
54
- b'type' : obj .dtype .str ,
55
- b'data' : obj .tobytes ()}
41
+ return {b'nd' : False ,
42
+ b'type' : obj .dtype .str ,
43
+ b'data' : obj .data }
56
44
elif isinstance (obj , complex ):
57
45
return {b'complex' : True ,
58
46
b'data' : obj .__repr__ ()}
@@ -104,9 +92,8 @@ def __init__(self, default=None,
104
92
encoding = 'utf-8' ,
105
93
unicode_errors = 'strict' ,
106
94
use_single_float = False ,
107
- autoreset = 1 ,
108
- copyless = False ):
109
- default = functools .partial (encode , chain = default , copyless = copyless )
95
+ autoreset = 1 ):
96
+ default = functools .partial (encode , chain = default )
110
97
super (Packer , self ).__init__ (default = default ,
111
98
encoding = encoding ,
112
99
unicode_errors = unicode_errors ,
@@ -135,9 +122,8 @@ def __init__(self, default=None,
135
122
unicode_errors = 'strict' ,
136
123
use_single_float = False ,
137
124
autoreset = 1 ,
138
- use_bin_type = 0 ,
139
- copyless = False ):
140
- default = functools .partial (encode , chain = default , copyless = copyless )
125
+ use_bin_type = 0 ):
126
+ default = functools .partial (encode , chain = default )
141
127
super (Packer , self ).__init__ (default = default ,
142
128
encoding = encoding ,
143
129
unicode_errors = unicode_errors ,
0 commit comments