4
4
import os
5
5
6
6
import numpy as np
7
+ import pandas as pd
7
8
import pytest
9
+ import xarray as xr
8
10
9
11
from .. import info
10
12
from ..exceptions import GMTInvalidInput
14
16
15
17
16
18
def test_info ():
17
- "Make sure info works"
18
- output = info (fname = POINTS_DATA )
19
+ "Make sure info works on file name inputs "
20
+ output = info (table = POINTS_DATA )
19
21
expected_output = (
20
22
f"{ POINTS_DATA } : N = 20 "
21
23
"<11.5309/61.7074> "
@@ -25,33 +27,61 @@ def test_info():
25
27
assert output == expected_output
26
28
27
29
30
+ def test_info_dataframe ():
31
+ "Make sure info works on pandas.DataFrame inputs"
32
+ table = pd .read_csv (POINTS_DATA , sep = " " , header = None )
33
+ output = info (table = table )
34
+ expected_output = (
35
+ "<matrix memory>: N = 20 <11.5309/61.7074> <-2.9289/7.8648> <0.1412/0.9338>\n "
36
+ )
37
+ assert output == expected_output
38
+
39
+
40
+ def test_info_2d_array ():
41
+ "Make sure info works on 2D numpy.ndarray inputs"
42
+ table = np .loadtxt (POINTS_DATA )
43
+ output = info (table = table )
44
+ expected_output = (
45
+ "<matrix memory>: N = 20 <11.5309/61.7074> <-2.9289/7.8648> <0.1412/0.9338>\n "
46
+ )
47
+ assert output == expected_output
48
+
49
+
50
+ def test_info_1d_array ():
51
+ "Make sure info works on 1D numpy.ndarray inputs"
52
+ output = info (table = np .arange (20 ))
53
+ expected_output = "<matrix memory>: N = 20 <0/19>\n "
54
+ assert output == expected_output
55
+
56
+
28
57
def test_info_per_column ():
29
58
"Make sure the per_column option works"
30
- output = info (fname = POINTS_DATA , per_column = True )
59
+ output = info (table = POINTS_DATA , per_column = True )
31
60
assert output == "11.5309 61.7074 -2.9289 7.8648 0.1412 0.9338\n "
32
61
33
62
34
63
def test_info_spacing ():
35
64
"Make sure the spacing option works"
36
- output = info (fname = POINTS_DATA , spacing = 0.1 )
65
+ output = info (table = POINTS_DATA , spacing = 0.1 )
37
66
assert output == "-R11.5/61.8/-3/7.9\n "
38
67
39
68
40
69
def test_info_per_column_spacing ():
41
70
"Make sure the per_column and spacing options work together"
42
- output = info (fname = POINTS_DATA , per_column = True , spacing = 0.1 )
71
+ output = info (table = POINTS_DATA , per_column = True , spacing = 0.1 )
43
72
assert output == "11.5 61.8 -3 7.9 0.1412 0.9338\n "
44
73
45
74
46
75
def test_info_nearest_multiple ():
47
76
"Make sure the nearest_multiple option works"
48
- output = info (fname = POINTS_DATA , nearest_multiple = 0.1 )
77
+ output = info (table = POINTS_DATA , nearest_multiple = 0.1 )
49
78
assert output == "-T11.5/61.8/0.1\n "
50
79
51
80
52
81
def test_info_fails ():
53
- "Make sure info raises an exception if not given a file name"
54
- with pytest .raises (GMTInvalidInput ):
55
- info (fname = 21 )
82
+ """
83
+ Make sure info raises an exception if not given either a file name, pandas
84
+ DataFrame, or numpy ndarray
85
+ """
56
86
with pytest .raises (GMTInvalidInput ):
57
- info (fname = np . arange ( 20 ))
87
+ info (table = xr . DataArray ( 21 ))
0 commit comments