6
6
import pytest
7
7
8
8
import pandas as pd
9
- import pandas .io .common as cmn
9
+ import pandas .io .common as icom
10
10
import pandas .util ._test_decorators as td
11
11
import pandas .util .testing as tm
12
12
from pandas .compat import (
@@ -55,36 +55,36 @@ class TestCommonIOCapabilities(object):
55
55
56
56
def test_expand_user (self ):
57
57
filename = '~/sometest'
58
- expanded_name = cmn ._expand_user (filename )
58
+ expanded_name = icom ._expand_user (filename )
59
59
60
60
assert expanded_name != filename
61
61
assert os .path .isabs (expanded_name )
62
62
assert os .path .expanduser (filename ) == expanded_name
63
63
64
64
def test_expand_user_normal_path (self ):
65
65
filename = '/somefolder/sometest'
66
- expanded_name = cmn ._expand_user (filename )
66
+ expanded_name = icom ._expand_user (filename )
67
67
68
68
assert expanded_name == filename
69
69
assert os .path .expanduser (filename ) == expanded_name
70
70
71
71
@td .skip_if_no ('pathlib' )
72
72
def test_stringify_path_pathlib (self ):
73
- rel_path = cmn ._stringify_path (Path ('.' ))
73
+ rel_path = icom ._stringify_path (Path ('.' ))
74
74
assert rel_path == '.'
75
- redundant_path = cmn ._stringify_path (Path ('foo//bar' ))
75
+ redundant_path = icom ._stringify_path (Path ('foo//bar' ))
76
76
assert redundant_path == os .path .join ('foo' , 'bar' )
77
77
78
78
@td .skip_if_no ('py.path' )
79
79
def test_stringify_path_localpath (self ):
80
80
path = os .path .join ('foo' , 'bar' )
81
81
abs_path = os .path .abspath (path )
82
82
lpath = LocalPath (path )
83
- assert cmn ._stringify_path (lpath ) == abs_path
83
+ assert icom ._stringify_path (lpath ) == abs_path
84
84
85
85
def test_stringify_path_fspath (self ):
86
86
p = CustomFSPath ('foo/bar.csv' )
87
- result = cmn ._stringify_path (p )
87
+ result = icom ._stringify_path (p )
88
88
assert result == 'foo/bar.csv'
89
89
90
90
@pytest .mark .parametrize ('extension,expected' , [
@@ -97,12 +97,12 @@ def test_stringify_path_fspath(self):
97
97
@pytest .mark .parametrize ('path_type' , path_types )
98
98
def test_infer_compression_from_path (self , extension , expected , path_type ):
99
99
path = path_type ('foo/bar.csv' + extension )
100
- compression = cmn ._infer_compression (path , compression = 'infer' )
100
+ compression = icom ._infer_compression (path , compression = 'infer' )
101
101
assert compression == expected
102
102
103
103
def test_get_filepath_or_buffer_with_path (self ):
104
104
filename = '~/sometest'
105
- filepath_or_buffer , _ , _ , should_close = cmn .get_filepath_or_buffer (
105
+ filepath_or_buffer , _ , _ , should_close = icom .get_filepath_or_buffer (
106
106
filename )
107
107
assert filepath_or_buffer != filename
108
108
assert os .path .isabs (filepath_or_buffer )
@@ -111,7 +111,7 @@ def test_get_filepath_or_buffer_with_path(self):
111
111
112
112
def test_get_filepath_or_buffer_with_buffer (self ):
113
113
input_buffer = StringIO ()
114
- filepath_or_buffer , _ , _ , should_close = cmn .get_filepath_or_buffer (
114
+ filepath_or_buffer , _ , _ , should_close = icom .get_filepath_or_buffer (
115
115
input_buffer )
116
116
assert filepath_or_buffer == input_buffer
117
117
assert not should_close
@@ -246,18 +246,18 @@ def test_constructor_bad_file(self, mmap_file):
246
246
msg = "[Errno 22]"
247
247
err = mmap .error
248
248
249
- tm .assert_raises_regex (err , msg , cmn .MMapWrapper , non_file )
249
+ tm .assert_raises_regex (err , msg , icom .MMapWrapper , non_file )
250
250
251
251
target = open (mmap_file , 'r' )
252
252
target .close ()
253
253
254
254
msg = "I/O operation on closed file"
255
255
tm .assert_raises_regex (
256
- ValueError , msg , cmn .MMapWrapper , target )
256
+ ValueError , msg , icom .MMapWrapper , target )
257
257
258
258
def test_get_attr (self , mmap_file ):
259
259
with open (mmap_file , 'r' ) as target :
260
- wrapper = cmn .MMapWrapper (target )
260
+ wrapper = icom .MMapWrapper (target )
261
261
262
262
attrs = dir (wrapper .mmap )
263
263
attrs = [attr for attr in attrs
@@ -271,7 +271,7 @@ def test_get_attr(self, mmap_file):
271
271
272
272
def test_next (self , mmap_file ):
273
273
with open (mmap_file , 'r' ) as target :
274
- wrapper = cmn .MMapWrapper (target )
274
+ wrapper = icom .MMapWrapper (target )
275
275
lines = target .readlines ()
276
276
277
277
for line in lines :
@@ -313,14 +313,14 @@ def test_compression_size(obj, method, compression_only):
313
313
def test_compression_size_fh (obj , method , compression_only ):
314
314
315
315
with tm .ensure_clean () as path :
316
- f , handles = cmn ._get_handle (path , 'w' , compression = compression_only )
316
+ f , handles = icom ._get_handle (path , 'w' , compression = compression_only )
317
317
with f :
318
318
getattr (obj , method )(f )
319
319
assert not f .closed
320
320
assert f .closed
321
321
compressed = os .path .getsize (path )
322
322
with tm .ensure_clean () as path :
323
- f , handles = cmn ._get_handle (path , 'w' , compression = None )
323
+ f , handles = icom ._get_handle (path , 'w' , compression = None )
324
324
with f :
325
325
getattr (obj , method )(f )
326
326
assert not f .closed
@@ -339,7 +339,7 @@ def test_dataframe_compression_defaults_to_infer(
339
339
# Test that DataFrame.to_* methods default to inferring compression from
340
340
# paths. GH 22004
341
341
input = pd .DataFrame ([[1.0 , 0 , - 4 ], [3.4 , 5 , 2 ]], columns = ['X' , 'Y' , 'Z' ])
342
- extension = cmn ._compression_to_extension [compression_only ]
342
+ extension = icom ._compression_to_extension [compression_only ]
343
343
with tm .ensure_clean ('compressed' + extension ) as path :
344
344
getattr (input , write_method )(path , ** write_kwargs )
345
345
output = read_method (path , compression = compression_only )
@@ -358,7 +358,7 @@ def test_series_compression_defaults_to_infer(
358
358
# Test that Series.to_* methods default to inferring compression from
359
359
# paths. GH 22004
360
360
input = pd .Series ([0 , 5 , - 2 , 10 ], name = 'X' )
361
- extension = cmn ._compression_to_extension [compression_only ]
361
+ extension = icom ._compression_to_extension [compression_only ]
362
362
with tm .ensure_clean ('compressed' + extension ) as path :
363
363
getattr (input , write_method )(path , ** write_kwargs )
364
364
output = read_method (path , compression = compression_only , ** read_kwargs )
@@ -377,7 +377,7 @@ def test_compression_warning(compression_only):
377
377
[12.32112 , 123123.2 , 321321.2 ]],
378
378
columns = ['X' , 'Y' , 'Z' ])
379
379
with tm .ensure_clean () as path :
380
- f , handles = cmn ._get_handle (path , 'w' , compression = compression_only )
380
+ f , handles = icom ._get_handle (path , 'w' , compression = compression_only )
381
381
with tm .assert_produces_warning (RuntimeWarning ,
382
382
check_stacklevel = False ):
383
383
with f :
0 commit comments