19
19
import numpy .ma as ma
20
20
from numpy .exceptions import VisibleDeprecationWarning
21
21
from numpy .lib ._iotools import ConverterError , ConversionWarning
22
+ from numpy .lib .npyio import recfromcsv , recfromtxt
22
23
from numpy .ma .testutils import assert_equal
23
24
from numpy .testing import (
24
25
assert_warns , assert_ , assert_raises_regex , assert_raises ,
@@ -1657,13 +1658,13 @@ def test_dtype_with_converters_and_usecols(self):
1657
1658
dmap = {'1:1' :0 , '1:n' :1 , 'm:1' :2 , 'm:n' :3 }
1658
1659
dtyp = [('e1' ,'i4' ),('e2' ,'i4' ),('e3' ,'i2' ),('n' , 'i1' )]
1659
1660
conv = {0 : int , 1 : int , 2 : int , 3 : lambda r : dmap [r .decode ()]}
1660
- test = np . lib . npyio . recfromcsv (TextIO (dstr ,), dtype = dtyp , delimiter = ',' ,
1661
- names = None , converters = conv )
1661
+ test = recfromcsv (TextIO (dstr ,), dtype = dtyp , delimiter = ',' ,
1662
+ names = None , converters = conv )
1662
1663
control = np .rec .array ([(1 ,5 ,- 1 ,0 ), (2 ,8 ,- 1 ,1 ), (3 ,3 ,- 2 ,3 )], dtype = dtyp )
1663
1664
assert_equal (test , control )
1664
- dtyp = [('e1' ,'i4' ),('e2' ,'i4' ),('n' , 'i1' )]
1665
- test = np . lib . npyio . recfromcsv (TextIO (dstr ,), dtype = dtyp , delimiter = ',' ,
1666
- usecols = (0 ,1 , 3 ), names = None , converters = conv )
1665
+ dtyp = [('e1' , 'i4' ), ('e2' , 'i4' ), ('n' , 'i1' )]
1666
+ test = recfromcsv (TextIO (dstr ,), dtype = dtyp , delimiter = ',' ,
1667
+ usecols = (0 , 1 , 3 ), names = None , converters = conv )
1667
1668
control = np .rec .array ([(1 ,5 ,0 ), (2 ,8 ,1 ), (3 ,3 ,3 )], dtype = dtyp )
1668
1669
assert_equal (test , control )
1669
1670
@@ -2297,14 +2298,14 @@ def test_recfromtxt(self):
2297
2298
#
2298
2299
data = TextIO ('A,B\n 0,1\n 2,3' )
2299
2300
kwargs = dict (delimiter = "," , missing_values = "N/A" , names = True )
2300
- test = np . lib . npyio . recfromtxt (data , ** kwargs )
2301
+ test = recfromtxt (data , ** kwargs )
2301
2302
control = np .array ([(0 , 1 ), (2 , 3 )],
2302
2303
dtype = [('A' , int ), ('B' , int )])
2303
2304
assert_ (isinstance (test , np .recarray ))
2304
2305
assert_equal (test , control )
2305
2306
#
2306
2307
data = TextIO ('A,B\n 0,1\n 2,N/A' )
2307
- test = np . lib . npyio . recfromtxt (data , dtype = None , usemask = True , ** kwargs )
2308
+ test = recfromtxt (data , dtype = None , usemask = True , ** kwargs )
2308
2309
control = ma .array ([(0 , 1 ), (2 , - 1 )],
2309
2310
mask = [(False , False ), (False , True )],
2310
2311
dtype = [('A' , int ), ('B' , int )])
@@ -2317,14 +2318,14 @@ def test_recfromcsv(self):
2317
2318
#
2318
2319
data = TextIO ('A,B\n 0,1\n 2,3' )
2319
2320
kwargs = dict (missing_values = "N/A" , names = True , case_sensitive = True )
2320
- test = np . lib . npyio . recfromcsv (data , dtype = None , ** kwargs )
2321
+ test = recfromcsv (data , dtype = None , ** kwargs )
2321
2322
control = np .array ([(0 , 1 ), (2 , 3 )],
2322
2323
dtype = [('A' , int ), ('B' , int )])
2323
2324
assert_ (isinstance (test , np .recarray ))
2324
2325
assert_equal (test , control )
2325
2326
#
2326
2327
data = TextIO ('A,B\n 0,1\n 2,N/A' )
2327
- test = np . lib . npyio . recfromcsv (data , dtype = None , usemask = True , ** kwargs )
2328
+ test = recfromcsv (data , dtype = None , usemask = True , ** kwargs )
2328
2329
control = ma .array ([(0 , 1 ), (2 , - 1 )],
2329
2330
mask = [(False , False ), (False , True )],
2330
2331
dtype = [('A' , int ), ('B' , int )])
@@ -2333,23 +2334,23 @@ def test_recfromcsv(self):
2333
2334
assert_equal (test .A , [0 , 2 ])
2334
2335
#
2335
2336
data = TextIO ('A,B\n 0,1\n 2,3' )
2336
- test = np . lib . npyio . recfromcsv (data , missing_values = 'N/A' ,)
2337
+ test = recfromcsv (data , missing_values = 'N/A' ,)
2337
2338
control = np .array ([(0 , 1 ), (2 , 3 )],
2338
2339
dtype = [('a' , int ), ('b' , int )])
2339
2340
assert_ (isinstance (test , np .recarray ))
2340
2341
assert_equal (test , control )
2341
2342
#
2342
2343
data = TextIO ('A,B\n 0,1\n 2,3' )
2343
2344
dtype = [('a' , int ), ('b' , float )]
2344
- test = np . lib . npyio . recfromcsv (data , missing_values = 'N/A' , dtype = dtype )
2345
+ test = recfromcsv (data , missing_values = 'N/A' , dtype = dtype )
2345
2346
control = np .array ([(0 , 1 ), (2 , 3 )],
2346
2347
dtype = dtype )
2347
2348
assert_ (isinstance (test , np .recarray ))
2348
2349
assert_equal (test , control )
2349
2350
2350
2351
#gh-10394
2351
2352
data = TextIO ('color\n "red"\n "blue"' )
2352
- test = np . lib . npyio . recfromcsv (data , converters = {0 : lambda x : x .strip (b'\" ' )})
2353
+ test = recfromcsv (data , converters = {0 : lambda x : x .strip (b'\" ' )})
2353
2354
control = np .array ([('red' ,), ('blue' ,)], dtype = [('color' , (bytes , 4 ))])
2354
2355
assert_equal (test .dtype , control .dtype )
2355
2356
assert_equal (test , control )
@@ -2621,7 +2622,7 @@ def test_recfromtxt(self, filename_type):
2621
2622
f .write ('A,B\n 0,1\n 2,3' )
2622
2623
2623
2624
kwargs = dict (delimiter = "," , missing_values = "N/A" , names = True )
2624
- test = np . lib . npyio . recfromtxt (path , ** kwargs )
2625
+ test = recfromtxt (path , ** kwargs )
2625
2626
control = np .array ([(0 , 1 ), (2 , 3 )],
2626
2627
dtype = [('A' , int ), ('B' , int )])
2627
2628
assert_ (isinstance (test , np .recarray ))
@@ -2635,8 +2636,10 @@ def test_recfromcsv(self, filename_type):
2635
2636
with open (path , 'w' ) as f :
2636
2637
f .write ('A,B\n 0,1\n 2,3' )
2637
2638
2638
- kwargs = dict (missing_values = "N/A" , names = True , case_sensitive = True )
2639
- test = np .lib .npyio .recfromcsv (path , dtype = None , ** kwargs )
2639
+ kwargs = dict (
2640
+ missing_values = "N/A" , names = True , case_sensitive = True
2641
+ )
2642
+ test = recfromcsv (path , dtype = None , ** kwargs )
2640
2643
control = np .array ([(0 , 1 ), (2 , 3 )],
2641
2644
dtype = [('A' , int ), ('B' , int )])
2642
2645
assert_ (isinstance (test , np .recarray ))
0 commit comments