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

Method _read_old_header

pandas/io/stata.py:1338–1427  ·  view source on GitHub ↗
(self, first_char: bytes)

Source from the content-addressed store, hash-verified

1336 raise ValueError
1337
1338 def _read_old_header(self, first_char: bytes) -> None:
1339 self._format_version = int(first_char[0])
1340 if self._format_version not in [
1341 102,
1342 103,
1343 104,
1344 105,
1345 108,
1346 110,
1347 111,
1348 113,
1349 114,
1350 115,
1351 ]:
1352 raise ValueError(_version_error.format(version=self._format_version))
1353 self._set_encoding()
1354 # Note 102 format will have a zero in this header position, so support
1355 # relies on little-endian being set whenever this value isn't one,
1356 # even though for later releases strictly speaking the value should
1357 # be either one or two to be valid
1358 self._byteorder = ">" if self._read_int8() == 0x1 else "<"
1359 self._filetype = self._read_int8()
1360 self._path_or_buf.read(1) # unused
1361
1362 self._nvar = self._read_uint16()
1363 self._nobs = self._get_nobs()
1364
1365 self._data_label = self._get_data_label()
1366
1367 if self._format_version >= 105:
1368 self._time_stamp = self._get_time_stamp()
1369
1370 # descriptors
1371 if self._format_version >= 111:
1372 typlist = [int(c) for c in self._path_or_buf.read(self._nvar)]
1373 else:
1374 buf = self._path_or_buf.read(self._nvar)
1375 typlistb = np.frombuffer(buf, dtype=np.uint8)
1376 typlist = []
1377 for tp in typlistb:
1378 if tp in self.OLD_TYPE_MAPPING:
1379 typlist.append(self.OLD_TYPE_MAPPING[tp])
1380 else:
1381 typlist.append(tp - 127) # bytes
1382
1383 try:
1384 self._typlist = [self.TYPE_MAP[typ] for typ in typlist]
1385 except ValueError as err:
1386 invalid_types = ",".join([str(x) for x in typlist])
1387 raise ValueError(f"cannot convert stata types [{invalid_types}]") from err
1388 try:
1389 self._dtyplist = [self.DTYPE_MAP[typ] for typ in typlist]
1390 except ValueError as err:
1391 invalid_dtypes = ",".join([str(x) for x in typlist])
1392 raise ValueError(f"cannot convert stata dtypes [{invalid_dtypes}]") from err
1393
1394 if self._format_version > 108:
1395 self._varlist = [

Callers 1

_read_headerMethod · 0.95

Calls 15

_set_encodingMethod · 0.95
_read_int8Method · 0.95
_read_uint16Method · 0.95
_get_nobsMethod · 0.95
_get_data_labelMethod · 0.95
_get_time_stampMethod · 0.95
_decodeMethod · 0.95
_read_int16_countMethod · 0.95
_get_fmtlistMethod · 0.95
_get_lbllistMethod · 0.95
_get_variable_labelsMethod · 0.95
_read_int32Method · 0.95

Tested by

no test coverage detected