File tree 3 files changed +15
-0
lines changed
3 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,12 @@ def _read_header(self):
279
279
# read file header
280
280
line1 = self ._get_row ()
281
281
if line1 != _correct_line1 :
282
+ if "**COMPRESSED**" in line1 :
283
+ # this was created with the PROC CPORT method and can't be read
284
+ # https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/movefile/p1bm6aqp3fw4uin1hucwh718f6kp.htm
285
+ raise ValueError (
286
+ "Header record indicates a CPORT file, which is not readable."
287
+ )
282
288
raise ValueError ("Header record is not an XPORT file." )
283
289
284
290
line2 = self ._get_row ()
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ def setup_method(self, datapath):
30
30
self .file02 = os .path .join (self .dirpath , "SSHSV1_A.xpt" )
31
31
self .file03 = os .path .join (self .dirpath , "DRXFCD_G.xpt" )
32
32
self .file04 = os .path .join (self .dirpath , "paxraw_d_short.xpt" )
33
+ self .file05 = os .path .join (self .dirpath , "DEMO_PUF.cpt" )
33
34
34
35
with td .file_leak_context ():
35
36
yield
@@ -157,3 +158,11 @@ def test_truncated_float_support(self):
157
158
158
159
data = read_sas (self .file04 , format = "xport" )
159
160
tm .assert_frame_equal (data .astype ("int64" ), data_csv )
161
+
162
+ def test_cport_header_found_raises (self ):
163
+ # Test with DEMO_PUF.cpt, the beginning of puf2019_1_fall.xpt
164
+ # from https://www.cms.gov/files/zip/puf2019.zip
165
+ # (despite the extension, it's a cpt file)
166
+ msg = "Header record indicates a CPORT file, which is not readable."
167
+ with pytest .raises (ValueError , match = msg ):
168
+ read_sas (self .file05 , format = "xport" )
You can’t perform that action at this time.
0 commit comments