Skip to content

FIX: Add endianness missing flag when reading data #9264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.16.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Bug Fixes




- Fixed bug on bug endian platforms which produced incorrect results in ``StataReader`` (:issue:`8688`).

- Bug in ``MultiIndex.has_duplicates`` when having many levels causes an indexer overflow (:issue:`9075`, :issue:`5873`)
- Bug in ``pivot`` and `unstack`` where ``nan`` values would break index alignment (:issue:`7466`)
Expand Down
6 changes: 5 additions & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ def __init__(self, path_or_buf, encoding='iso-8859-1'):
self._missing_values = False
self._data_read = False
self._value_labels_read = False
self._native_byteorder = _set_endianness(sys.byteorder)
if isinstance(path_or_buf, str):
path_or_buf, encoding = get_filepath_or_buffer(
path_or_buf, encoding=self._default_encoding
Expand Down Expand Up @@ -1195,13 +1196,16 @@ def data(self, convert_dates=True, convert_categoricals=True, index=None,
dtype = [] # Convert struct data types to numpy data type
for i, typ in enumerate(self.typlist):
if typ in self.NUMPY_TYPE_MAP:
dtype.append(('s' + str(i), self.NUMPY_TYPE_MAP[typ]))
dtype.append(('s' + str(i), self.byteorder + self.NUMPY_TYPE_MAP[typ]))
else:
dtype.append(('s' + str(i), 'S' + str(typ)))
dtype = np.dtype(dtype)
read_len = count * dtype.itemsize
self.path_or_buf.seek(self.data_location)
data = np.frombuffer(self.path_or_buf.read(read_len),dtype=dtype,count=count)
# if necessary, swap the byte order to native here
if self.byteorder != self._native_byteorder:
data = data.byteswap().newbyteorder()
self._data_read = True

if convert_categoricals:
Expand Down