| 158 | |
| 159 | |
| 160 | def _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 | |
| 179 | def _parse_float_vec(vec): |