Skip to content

Commit e4bda82

Browse files
committed
BUG: Fix error in stata writer testing
Fix bug Restore previously deleted test since recarrays are back
1 parent 6272fbd commit e4bda82

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

statsmodels/iolib/tests/test_foreign.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,25 @@ def test_genfromdta_pandas():
4646
assert_frame_equal(res1, dta.astype(float))
4747

4848

49+
def test_stata_writer_structured():
50+
buf = BytesIO()
51+
dta = macrodata.load(as_pandas=False).data
52+
dtype = dta.dtype
53+
dt = [('year', int), ('quarter', int)] + dtype.descr[2:]
54+
if not PY3: # Remove unicode
55+
dt = [(name.encode('ascii'), typ) for name, typ in dt]
56+
dta = dta.astype(np.dtype(dt))
57+
writer = StataWriter(buf, dta)
58+
writer.write_file()
59+
buf.seek(0)
60+
dta2 = genfromdta(buf)
61+
assert_array_equal(dta, dta2)
62+
63+
4964
def test_stata_writer_array():
5065
buf = BytesIO()
5166
dta = macrodata.load(as_pandas=False).data
52-
dta = DataFrame.from_records(dta, index='index')
67+
dta = DataFrame.from_records(dta)
5368
dta.columns = ["v%d" % i for i in range(1,15)]
5469
writer = StataWriter(buf, dta.values)
5570
writer.write_file()
@@ -58,7 +73,6 @@ def test_stata_writer_array():
5873
dta = dta.to_records(index=False)
5974
assert_array_equal(dta, dta2)
6075

61-
6276
def test_missing_roundtrip():
6377
buf = BytesIO()
6478
dta = np.array([(np.nan, np.inf, "")],

0 commit comments

Comments
 (0)