33import csv
44from functools import partial
55import io
6- import os .path
76import pathlib
87from pathlib import Path
98import sqlite3
6564from pandas .io .stata import StataReader
6665
6766DF = DataFrame ({"a" : [1 , 2 , 3 ], "b" : [0.0 , 0.0 , 0.0 ]})
68- CWD = os . path . split ( os . path . abspath ( __file__ ))[ 0 ]
67+ CWD = Path ( __file__ ). parent . resolve ()
6968
7069
7170@pytest .mark .skipif (WINDOWS , reason = "ORC not available on windows" )
@@ -86,10 +85,10 @@ def test_orc_path() -> None:
8685@pytest .mark .skipif (WINDOWS , reason = "ORC not available on windows" )
8786def test_orc_buffer () -> None :
8887 with ensure_clean () as path :
89- with open (path , "wb" ) as file_w :
88+ with Path (path ). open ( "wb" ) as file_w :
9089 check (assert_type (DF .to_orc (file_w ), None ), type (None ))
9190
92- with open (path , "rb" ) as file_r :
91+ with Path (path ). open ( "rb" ) as file_r :
9392 check (assert_type (read_orc (file_r ), DataFrame ), DataFrame )
9493
9594
@@ -109,7 +108,7 @@ def test_xml() -> None:
109108 with ensure_clean () as path :
110109 check (assert_type (DF .to_xml (path ), None ), type (None ))
111110 check (assert_type (read_xml (path ), DataFrame ), DataFrame )
112- with open (path , "rb" ) as f :
111+ with Path (path ). open ( "rb" ) as f :
113112 check (assert_type (read_xml (f ), DataFrame ), DataFrame )
114113
115114
@@ -128,7 +127,7 @@ def test_pickle() -> None:
128127def test_pickle_file_handle () -> None :
129128 with ensure_clean () as path :
130129 check (assert_type (DF .to_pickle (path ), None ), type (None ))
131- with open (path , "rb" ) as file :
130+ with Path (path ). open ( "rb" ) as file :
132131 check (assert_type (read_pickle (file ), Any ), DataFrame )
133132
134133
@@ -562,9 +561,9 @@ def test_read_csv() -> None:
562561 with ensure_clean () as path :
563562 check (assert_type (DF .to_csv (path ), None ), type (None ))
564563 check (assert_type (read_csv (path ), DataFrame ), DataFrame )
565- with open (path ) as csv_file :
564+ with Path (path ). open ( ) as csv_file :
566565 check (assert_type (read_csv (csv_file ), DataFrame ), DataFrame )
567- with open (path ) as csv_file :
566+ with Path (path ). open ( ) as csv_file :
568567 sio = io .StringIO (csv_file .read ())
569568 check (assert_type (read_csv (sio ), DataFrame ), DataFrame )
570569 check (assert_type (read_csv (path , iterator = False ), DataFrame ), DataFrame )
@@ -917,15 +916,15 @@ def test_btest_read_fwf() -> None:
917916 check (assert_type (read_fwf (path ), DataFrame ), DataFrame )
918917 check (assert_type (read_fwf (pathlib .Path (path )), DataFrame ), DataFrame )
919918
920- with open (path ) as fwf_file :
919+ with Path (path ). open ( ) as fwf_file :
921920 check (
922921 assert_type (read_fwf (fwf_file ), DataFrame ),
923922 DataFrame ,
924923 )
925- with open (path ) as fwf_file :
924+ with Path (path ). open ( ) as fwf_file :
926925 sio = io .StringIO (fwf_file .read ())
927926 check (assert_type (read_fwf (sio ), DataFrame ), DataFrame )
928- with open (path , "rb" ) as fwf_file :
927+ with Path (path ). open ( "rb" ) as fwf_file :
929928 bio = io .BytesIO (fwf_file .read ())
930929 check (assert_type (read_fwf (bio ), DataFrame ), DataFrame )
931930 with read_fwf (path , iterator = True ) as fwf_iterator :
@@ -1228,7 +1227,7 @@ def test_to_string() -> None:
12281227 with ensure_clean () as path :
12291228 check (assert_type (DF .to_string (path ), None ), type (None ))
12301229 check (assert_type (DF .to_string (pathlib .Path (path )), None ), type (None ))
1231- with open (path , "w" ) as df_string :
1230+ with Path (path ). open ( "w" ) as df_string :
12321231 check (assert_type (DF .to_string (df_string ), None ), type (None ))
12331232 sio = io .StringIO ()
12341233 check (assert_type (DF .to_string (sio ), None ), type (None ))
0 commit comments