@@ -1024,28 +1024,29 @@ def test_read_chunks_117(self):
1024
1024
check_datetimelike_compat = True )
1025
1025
1026
1026
pos += chunksize
1027
+ itr .close ()
1027
1028
1028
1029
def test_iterator (self ):
1029
1030
1030
1031
fname = self .dta3_117
1031
1032
1032
1033
parsed = read_stata (fname )
1033
1034
1034
- itr = read_stata (fname , iterator = True )
1035
- chunk = itr .read (5 )
1036
- tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk )
1035
+ with read_stata (fname , iterator = True ) as itr :
1036
+ chunk = itr .read (5 )
1037
+ tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk )
1037
1038
1038
- itr = read_stata (fname , chunksize = 5 )
1039
- chunk = list (itr )
1040
- tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk [0 ])
1039
+ with read_stata (fname , chunksize = 5 ) as itr :
1040
+ chunk = list (itr )
1041
+ tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk [0 ])
1041
1042
1042
- itr = read_stata (fname , iterator = True )
1043
- chunk = itr .get_chunk (5 )
1044
- tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk )
1043
+ with read_stata (fname , iterator = True ) as itr :
1044
+ chunk = itr .get_chunk (5 )
1045
+ tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk )
1045
1046
1046
- itr = read_stata (fname , chunksize = 5 )
1047
- chunk = itr .get_chunk ()
1048
- tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk )
1047
+ with read_stata (fname , chunksize = 5 ) as itr :
1048
+ chunk = itr .get_chunk ()
1049
+ tm .assert_frame_equal (parsed .iloc [0 :5 , :], chunk )
1049
1050
1050
1051
# GH12153
1051
1052
from_chunks = pd .concat (read_stata (fname , chunksize = 4 ))
@@ -1089,22 +1090,23 @@ def test_read_chunks_115(self):
1089
1090
check_datetimelike_compat = True )
1090
1091
1091
1092
pos += chunksize
1093
+ itr .close ()
1092
1094
1093
1095
def test_read_chunks_columns (self ):
1094
1096
fname = self .dta3_117
1095
1097
columns = ['quarter' , 'cpi' , 'm1' ]
1096
1098
chunksize = 2
1097
1099
1098
1100
parsed = read_stata (fname , columns = columns )
1099
- itr = read_stata (fname , iterator = True )
1100
- pos = 0
1101
- for j in range (5 ):
1102
- chunk = itr .read (chunksize , columns = columns )
1103
- if chunk is None :
1104
- break
1105
- from_frame = parsed .iloc [pos :pos + chunksize , :]
1106
- tm .assert_frame_equal (from_frame , chunk , check_dtype = False )
1107
- pos += chunksize
1101
+ with read_stata (fname , iterator = True ) as itr :
1102
+ pos = 0
1103
+ for j in range (5 ):
1104
+ chunk = itr .read (chunksize , columns = columns )
1105
+ if chunk is None :
1106
+ break
1107
+ from_frame = parsed .iloc [pos :pos + chunksize , :]
1108
+ tm .assert_frame_equal (from_frame , chunk , check_dtype = False )
1109
+ pos += chunksize
1108
1110
1109
1111
1110
1112
if __name__ == '__main__' :
0 commit comments