Skip to content

Commit fa914cc

Browse files
committed
Merge pull request #8982 from bashtage/stata-large-int-missing-value
FIX: Workaround for integer hashing
2 parents 4ab5409 + 802917c commit fa914cc

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

pandas/io/stata.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,10 @@ class StataMissingValue(StringMixin):
611611
MISSING_VALUES = {}
612612
bases = (101, 32741, 2147483621)
613613
for b in bases:
614-
MISSING_VALUES[b] = '.'
614+
# Conversion to long to avoid hash issues on 32 bit platforms #8968
615+
MISSING_VALUES[compat.long(b)] = '.'
615616
for i in range(1, 27):
616-
MISSING_VALUES[i + b] = '.' + chr(96 + i)
617+
MISSING_VALUES[compat.long(i + b)] = '.' + chr(96 + i)
617618

618619
float32_base = b'\x00\x00\x00\x7f'
619620
increment = struct.unpack('<i', b'\x00\x08\x00\x00')[0]
@@ -643,6 +644,8 @@ class StataMissingValue(StringMixin):
643644

644645
def __init__(self, value):
645646
self._value = value
647+
# Conversion to long to avoid hash issues on 32 bit platforms #8968
648+
value = compat.long(value) if value < 2147483648 else float(value)
646649
self._str = self.MISSING_VALUES[value]
647650

648651
string = property(lambda self: self._str,
@@ -1375,13 +1378,6 @@ def _pad_bytes(name, length):
13751378
return name + "\x00" * (length - len(name))
13761379

13771380

1378-
def _default_names(nvar):
1379-
"""
1380-
Returns default Stata names v1, v2, ... vnvar
1381-
"""
1382-
return ["v%d" % i for i in range(1, nvar+1)]
1383-
1384-
13851381
def _convert_datetime_to_stata_type(fmt):
13861382
"""
13871383
Converts from one of the stata date formats to a type in TYPE_MAP

0 commit comments

Comments
 (0)