12
12
DataFrame ,
13
13
Index ,
14
14
MultiIndex ,
15
+ NaT ,
15
16
Series ,
16
17
Timestamp ,
17
18
date_range ,
@@ -41,7 +42,7 @@ def read_csv(self, path, **kwargs):
41
42
params = {"index_col" : 0 , "parse_dates" : True }
42
43
params .update (** kwargs )
43
44
44
- return pd . read_csv (path , ** params )
45
+ return read_csv (path , ** params )
45
46
46
47
def test_to_csv_from_csv1 (self , float_frame , datetime_frame ):
47
48
@@ -123,7 +124,7 @@ def test_to_csv_from_csv3(self):
123
124
df1 .to_csv (path )
124
125
df2 .to_csv (path , mode = "a" , header = False )
125
126
xp = pd .concat ([df1 , df2 ])
126
- rs = pd . read_csv (path , index_col = 0 )
127
+ rs = read_csv (path , index_col = 0 )
127
128
rs .columns = [int (label ) for label in rs .columns ]
128
129
xp .columns = [int (label ) for label in xp .columns ]
129
130
tm .assert_frame_equal (xp , rs )
@@ -139,7 +140,7 @@ def test_to_csv_from_csv4(self):
139
140
)
140
141
df .to_csv (path )
141
142
142
- result = pd . read_csv (path , index_col = "dt_index" )
143
+ result = read_csv (path , index_col = "dt_index" )
143
144
result .index = pd .to_timedelta (result .index )
144
145
# TODO: remove renaming when GH 10875 is solved
145
146
result .index = result .index .rename ("dt_index" )
@@ -153,7 +154,7 @@ def test_to_csv_from_csv5(self, timezone_frame):
153
154
with tm .ensure_clean ("__tmp_to_csv_from_csv5__" ) as path :
154
155
155
156
timezone_frame .to_csv (path )
156
- result = pd . read_csv (path , index_col = 0 , parse_dates = ["A" ])
157
+ result = read_csv (path , index_col = 0 , parse_dates = ["A" ])
157
158
158
159
converter = (
159
160
lambda c : to_datetime (result [c ])
@@ -166,8 +167,6 @@ def test_to_csv_from_csv5(self, timezone_frame):
166
167
167
168
def test_to_csv_cols_reordering (self ):
168
169
# GH3454
169
- import pandas as pd
170
-
171
170
chunksize = 5
172
171
N = int (chunksize * 2.5 )
173
172
@@ -177,17 +176,15 @@ def test_to_csv_cols_reordering(self):
177
176
178
177
with tm .ensure_clean () as path :
179
178
df .to_csv (path , columns = cols , chunksize = chunksize )
180
- rs_c = pd . read_csv (path , index_col = 0 )
179
+ rs_c = read_csv (path , index_col = 0 )
181
180
182
181
tm .assert_frame_equal (df [cols ], rs_c , check_names = False )
183
182
184
183
def test_to_csv_new_dupe_cols (self ):
185
- import pandas as pd
186
-
187
184
def _check_df (df , cols = None ):
188
185
with tm .ensure_clean () as path :
189
186
df .to_csv (path , columns = cols , chunksize = chunksize )
190
- rs_c = pd . read_csv (path , index_col = 0 )
187
+ rs_c = read_csv (path , index_col = 0 )
191
188
192
189
# we wrote them in a different order
193
190
# so compare them in that order
@@ -227,8 +224,6 @@ def _check_df(df, cols=None):
227
224
@pytest .mark .slow
228
225
def test_to_csv_dtnat (self ):
229
226
# GH3437
230
- from pandas import NaT
231
-
232
227
def make_dtnat_arr (n , nnat = None ):
233
228
if nnat is None :
234
229
nnat = int (n * 0.1 ) # 10%
@@ -999,7 +994,7 @@ def test_to_csv_path_is_none(self, float_frame):
999
994
# Series.to_csv()
1000
995
csv_str = float_frame .to_csv (path_or_buf = None )
1001
996
assert isinstance (csv_str , str )
1002
- recons = pd . read_csv (StringIO (csv_str ), index_col = 0 )
997
+ recons = read_csv (StringIO (csv_str ), index_col = 0 )
1003
998
tm .assert_frame_equal (float_frame , recons )
1004
999
1005
1000
@pytest .mark .parametrize (
@@ -1040,7 +1035,7 @@ def test_to_csv_compression(self, df, encoding, compression):
1040
1035
df .to_csv (handles .handle , encoding = encoding )
1041
1036
assert not handles .handle .closed
1042
1037
1043
- result = pd . read_csv (
1038
+ result = read_csv (
1044
1039
filename ,
1045
1040
compression = compression ,
1046
1041
encoding = encoding ,
@@ -1122,7 +1117,7 @@ def test_to_csv_with_dst_transitions(self):
1122
1117
1123
1118
with tm .ensure_clean ("csv_date_format_with_dst" ) as path :
1124
1119
# make sure we are not failing on transitions
1125
- times = pd . date_range (
1120
+ times = date_range (
1126
1121
"2013-10-26 23:00" ,
1127
1122
"2013-10-27 01:00" ,
1128
1123
tz = "Europe/London" ,
@@ -1144,7 +1139,7 @@ def test_to_csv_with_dst_transitions(self):
1144
1139
tm .assert_frame_equal (result , df )
1145
1140
1146
1141
# GH11619
1147
- idx = pd . date_range ("2015-01-01" , "2015-12-31" , freq = "H" , tz = "Europe/Paris" )
1142
+ idx = date_range ("2015-01-01" , "2015-12-31" , freq = "H" , tz = "Europe/Paris" )
1148
1143
idx = idx ._with_freq (None ) # freq does not round-trip
1149
1144
idx ._data ._freq = None # otherwise there is trouble on unpickle
1150
1145
df = DataFrame ({"values" : 1 , "idx" : idx }, index = idx )
@@ -1250,7 +1245,7 @@ def test_to_csv_quoting(self):
1250
1245
# presents with encoding?
1251
1246
text_rows = ["a,b,c" , '1,"test \r \n ",3' ]
1252
1247
text = tm .convert_rows_list_to_csv_str (text_rows )
1253
- df = pd . read_csv (StringIO (text ))
1248
+ df = read_csv (StringIO (text ))
1254
1249
1255
1250
buf = StringIO ()
1256
1251
df .to_csv (buf , encoding = "utf-8" , index = False )
@@ -1286,7 +1281,7 @@ def test_period_index_date_overflow(self):
1286
1281
assert result == expected
1287
1282
1288
1283
# Overflow with pd.NaT
1289
- dates = ["1990-01-01" , pd . NaT , "3005-01-01" ]
1284
+ dates = ["1990-01-01" , NaT , "3005-01-01" ]
1290
1285
index = pd .PeriodIndex (dates , freq = "D" )
1291
1286
1292
1287
df = DataFrame ([4 , 5 , 6 ], index = index )
@@ -1298,7 +1293,7 @@ def test_period_index_date_overflow(self):
1298
1293
1299
1294
def test_multi_index_header (self ):
1300
1295
# see gh-5539
1301
- columns = pd . MultiIndex .from_tuples ([("a" , 1 ), ("a" , 2 ), ("b" , 1 ), ("b" , 2 )])
1296
+ columns = MultiIndex .from_tuples ([("a" , 1 ), ("a" , 2 ), ("b" , 1 ), ("b" , 2 )])
1302
1297
df = DataFrame ([[1 , 2 , 3 , 4 ], [5 , 6 , 7 , 8 ]])
1303
1298
df .columns = columns
1304
1299
0 commit comments