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

Class StataReader

pandas/io/stata.py:1022–2086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1020
1021@set_module("pandas.api.typing")
1022class StataReader(StataParser, abc.Iterator):
1023 __doc__ = _stata_reader_doc
1024
1025 _path_or_buf: IO[bytes] # Will be assigned by `_open_file`.
1026
1027 def __init__(
1028 self,
1029 path_or_buf: FilePath | ReadBuffer[bytes],
1030 convert_dates: bool = True,
1031 convert_categoricals: bool = True,
1032 index_col: str | None = None,
1033 convert_missing: bool = False,
1034 preserve_dtypes: bool = True,
1035 columns: Sequence[str] | None = None,
1036 order_categoricals: bool = True,
1037 chunksize: int | None = None,
1038 compression: CompressionOptions = "infer",
1039 storage_options: StorageOptions | None = None,
1040 ) -> None:
1041 super().__init__()
1042
1043 # Arguments to the reader (can be temporarily overridden in
1044 # calls to read).
1045 self._convert_dates = convert_dates
1046 self._convert_categoricals = convert_categoricals
1047 self._index_col = index_col
1048 self._convert_missing = convert_missing
1049 self._preserve_dtypes = preserve_dtypes
1050 self._columns = columns
1051 self._order_categoricals = order_categoricals
1052 self._original_path_or_buf = path_or_buf
1053 self._compression = compression
1054 self._storage_options = storage_options
1055 self._encoding = ""
1056 self._chunksize = chunksize
1057 self._using_iterator = False
1058 self._entered = False
1059 if self._chunksize is None:
1060 self._chunksize = 1
1061 elif not isinstance(chunksize, int) or chunksize <= 0:
1062 raise ValueError("chunksize must be a positive integer when set.")
1063
1064 # State variables for the file
1065 self._close_file: Callable[[], None] | None = None
1066 self._column_selector_set = False
1067 self._value_label_dict: dict[str, dict[int, str]] = {}
1068 self._value_labels_read = False
1069 self._dtype: np.dtype | None = None
1070 self._lines_read = 0
1071
1072 self._native_byteorder = _set_endianness(sys.byteorder)
1073
1074 def _ensure_open(self) -> None:
1075 """
1076 Ensure the file has been opened and its header data read.
1077 """
1078 if not hasattr(self, "_path_or_buf"):
1079 self._open_file()

Callers 15

test_read_dta118_119Method · 0.90
test_variable_labelsMethod · 0.90
test_minimal_size_colMethod · 0.90
test_stata_119Method · 0.90
test_utf8_writerMethod · 0.90
test_direct_readFunction · 0.90
test_chunked_categoricalFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_read_dta118_119Method · 0.72
test_variable_labelsMethod · 0.72
test_minimal_size_colMethod · 0.72
test_stata_119Method · 0.72
test_utf8_writerMethod · 0.72
test_direct_readFunction · 0.72
test_chunked_categoricalFunction · 0.72