MCPcopy
hub / github.com/pandas-dev/pandas / _handle_truncated_float_vec

Function _handle_truncated_float_vec

pandas/io/sas/sas_xport.py:160–176  ·  view source on GitHub ↗
(vec, nbytes)

Source from the content-addressed store, hash-verified

158
159
160def _handle_truncated_float_vec(vec, nbytes):
161 # This feature is not well documented, but some SAS XPORT files
162 # have 2-7 byte "truncated" floats. To read these truncated
163 # floats, pad them with zeros on the right to make 8 byte floats.
164 #
165 # References:
166 # https://github.com/jcushman/xport/pull/3
167 # The R "foreign" library
168
169 if nbytes != 8:
170 vec1 = np.zeros(len(vec), np.dtype("S8"))
171 dtype = np.dtype(f"S{nbytes},S{8 - nbytes}")
172 vec2 = vec1.view(dtype=dtype)
173 vec2["f0"] = vec
174 return vec2
175
176 return vec
177
178
179def _parse_float_vec(vec):

Callers 1

readMethod · 0.85

Calls 2

dtypeMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected