Skip to content

Commit 5af55e0

Browse files
authored
BUG: Missing value code not recognised for Stata format version 105 a… (#59325)
* BUG: Missing value code not recognised for Stata format version 105 and earlier * Move definition of the old missing value constant for the double type out of the loop
1 parent 0e0814b commit 5af55e0

File tree

11 files changed

+38
-11
lines changed

11 files changed

+38
-11
lines changed

doc/source/whatsnew/v3.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ I/O
584584
- Bug in :meth:`read_json` not validating the ``typ`` argument to not be exactly ``"frame"`` or ``"series"`` (:issue:`59124`)
585585
- Bug in :meth:`read_stata` raising ``KeyError`` when input file is stored in big-endian format and contains strL data. (:issue:`58638`)
586586
- Bug in :meth:`read_stata` where extreme value integers were incorrectly interpreted as missing for format versions 111 and prior (:issue:`58130`)
587+
- Bug in :meth:`read_stata` where the missing code for double was not recognised for format versions 105 and prior (:issue:`58149`)
587588

588589
Period
589590
^^^^^^

pandas/io/stata.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,10 +1817,19 @@ def read(
18171817
return data
18181818

18191819
def _do_convert_missing(self, data: DataFrame, convert_missing: bool) -> DataFrame:
1820+
# missing code for double was different in version 105 and prior
1821+
old_missingdouble = float.fromhex("0x1.0p333")
1822+
18201823
# Check for missing values, and replace if found
18211824
replacements = {}
18221825
for i in range(len(data.columns)):
18231826
fmt = self._typlist[i]
1827+
# recode instances of the old missing code to the currently used value
1828+
if self._format_version <= 105 and fmt == "d":
1829+
data.iloc[:, i] = data.iloc[:, i].replace(
1830+
old_missingdouble, self.MISSING_VALUES["d"]
1831+
)
1832+
18241833
if self._format_version <= 111:
18251834
if fmt not in self.OLD_VALID_RANGE:
18261835
continue
362 Bytes
Binary file not shown.
364 Bytes
Binary file not shown.
363 Bytes
Binary file not shown.
409 Bytes
Binary file not shown.
362 Bytes
Binary file not shown.
364 Bytes
Binary file not shown.
363 Bytes
Binary file not shown.
409 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)