Skip to content

Commit 846add0

Browse files
seismanweiji14
andauthored
pygmt.info: Deprecate parameter "table" to "data" (remove in v0.7.0) (#1538)
Co-authored-by: Wei Ji <[email protected]>
1 parent 09847a7 commit 846add0

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

pygmt/src/info.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
from pygmt.helpers import (
77
GMTTempFile,
88
build_arg_string,
9+
deprecate_parameter,
910
fmt_docstring,
1011
kwargs_to_strings,
1112
use_alias,
1213
)
1314

1415

1516
@fmt_docstring
17+
@deprecate_parameter("table", "data", "v0.5.0", remove_version="v0.7.0")
1618
@use_alias(
1719
C="per_column",
1820
I="spacing",
@@ -24,7 +26,7 @@
2426
r="registration",
2527
)
2628
@kwargs_to_strings(I="sequence", i="sequence_comma")
27-
def info(table, **kwargs):
29+
def info(data, **kwargs):
2830
r"""
2931
Get information about data tables.
3032
@@ -47,7 +49,7 @@ def info(table, **kwargs):
4749
4850
Parameters
4951
----------
50-
table : str or {table-like}
52+
data : str or {table-like}
5153
Pass in either a file name to an ASCII data table, a 1D/2D
5254
{table-classes}.
5355
per_column : bool
@@ -80,7 +82,7 @@ def info(table, **kwargs):
8082
- str if none of the above parameters are used.
8183
"""
8284
with Session() as lib:
83-
file_context = lib.virtualfile_from_data(data=table)
85+
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
8486
with GMTTempFile() as tmpfile:
8587
with file_context as fname:
8688
arg_str = " ".join(

pygmt/tests/test_geopandas.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_geopandas_info_geodataframe(gdf):
4444
Check that info can return the bounding box region from a
4545
geopandas.GeoDataFrame.
4646
"""
47-
output = info(table=gdf, per_column=True)
47+
output = info(data=gdf, per_column=True)
4848
npt.assert_allclose(actual=output, desired=[0.0, 35.0, 0.0, 20.0])
4949

5050

@@ -62,7 +62,7 @@ def test_geopandas_info_shapely(gdf, geomtype, desired):
6262
object that has a __geo_interface__ property.
6363
"""
6464
geom = gdf.loc[geomtype].geometry
65-
output = info(table=geom, per_column=True)
65+
output = info(data=geom, per_column=True)
6666
npt.assert_allclose(actual=output, desired=desired)
6767

6868

pygmt/tests/test_info.py

+33-16
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_info():
2121
"""
2222
Make sure info works on file name inputs.
2323
"""
24-
output = info(table=POINTS_DATA)
24+
output = info(data=POINTS_DATA)
2525
expected_output = (
2626
f"{POINTS_DATA}: N = 20 "
2727
"<11.5309/61.7074> "
@@ -31,6 +31,23 @@ def test_info():
3131
assert output == expected_output
3232

3333

34+
def test_info_deprecate_table_to_data():
35+
"""
36+
Make sure that the old parameter "table" is supported and it reports a
37+
warning.
38+
"""
39+
with pytest.warns(expected_warning=FutureWarning) as record:
40+
output = info(table=POINTS_DATA) # pylint: disable=no-value-for-parameter
41+
expected_output = (
42+
f"{POINTS_DATA}: N = 20 "
43+
"<11.5309/61.7074> "
44+
"<-2.9289/7.8648> "
45+
"<0.1412/0.9338>\n"
46+
)
47+
assert output == expected_output
48+
assert len(record) == 1 # check that only one warning was raised
49+
50+
3451
@pytest.mark.parametrize(
3552
"table",
3653
[
@@ -55,7 +72,7 @@ def test_info_path(table):
5572
"""
5673
Make sure info works on a pathlib.Path input.
5774
"""
58-
output = info(table=table)
75+
output = info(data=table)
5976
expected_output = (
6077
f"{POINTS_DATA}: N = 20 "
6178
"<11.5309/61.7074> "
@@ -69,7 +86,7 @@ def test_info_2d_list():
6986
"""
7087
Make sure info works on a 2d list.
7188
"""
72-
output = info(table=[[0, 8], [3, 5], [6, 2]])
89+
output = info(data=[[0, 8], [3, 5], [6, 2]])
7390
expected_output = "<vector memory>: N = 3 <0/6> <2/8>\n"
7491
assert output == expected_output
7592

@@ -88,7 +105,7 @@ def test_info_dataframe():
88105
Make sure info works on pandas.DataFrame inputs.
89106
"""
90107
table = pd.read_csv(POINTS_DATA, sep=" ", header=None)
91-
output = info(table=table)
108+
output = info(data=table)
92109
expected_output = (
93110
"<vector memory>: N = 20 <11.5309/61.7074> <-2.9289/7.8648> <0.1412/0.9338>\n"
94111
)
@@ -100,7 +117,7 @@ def test_info_numpy_array_time_column():
100117
Make sure info works on a numpy.ndarray input with a datetime type.
101118
"""
102119
table = pd.date_range(start="2020-01-01", periods=5).to_numpy()
103-
output = info(table=table)
120+
output = info(data=table)
104121
expected_output = (
105122
"<vector memory>: N = 5 <2020-01-01T00:00:00/2020-01-05T00:00:00>\n"
106123
)
@@ -117,7 +134,7 @@ def test_info_pandas_dataframe_time_column():
117134
"time": pd.date_range(start="2020-01-01", periods=5),
118135
}
119136
)
120-
output = info(table=table)
137+
output = info(data=table)
121138
expected_output = (
122139
"<vector memory>: N = 5 <10/15> <2020-01-01T00:00:00/2020-01-05T00:00:00>\n"
123140
)
@@ -135,7 +152,7 @@ def test_info_xarray_dataset_time_column():
135152
"time": ("index", pd.date_range(start="2020-01-01", periods=5)),
136153
},
137154
)
138-
output = info(table=table)
155+
output = info(data=table)
139156
expected_output = (
140157
"<vector memory>: N = 5 <10/15> <2020-01-01T00:00:00/2020-01-05T00:00:00>\n"
141158
)
@@ -147,7 +164,7 @@ def test_info_2d_array():
147164
Make sure info works on 2D numpy.ndarray inputs.
148165
"""
149166
table = np.loadtxt(POINTS_DATA)
150-
output = info(table=table)
167+
output = info(data=table)
151168
expected_output = (
152169
"<matrix memory>: N = 20 <11.5309/61.7074> <-2.9289/7.8648> <0.1412/0.9338>\n"
153170
)
@@ -158,7 +175,7 @@ def test_info_1d_array():
158175
"""
159176
Make sure info works on 1D numpy.ndarray inputs.
160177
"""
161-
output = info(table=np.arange(20))
178+
output = info(data=np.arange(20))
162179
expected_output = "<vector memory>: N = 20 <0/19>\n"
163180
assert output == expected_output
164181

@@ -167,7 +184,7 @@ def test_info_per_column():
167184
"""
168185
Make sure the per_column option works.
169186
"""
170-
output = info(table=POINTS_DATA, per_column=True)
187+
output = info(data=POINTS_DATA, per_column=True)
171188
npt.assert_allclose(
172189
actual=output, desired=[11.5309, 61.7074, -2.9289, 7.8648, 0.1412, 0.9338]
173190
)
@@ -178,7 +195,7 @@ def test_info_per_column_with_time_inputs():
178195
Make sure the per_column option works with time inputs.
179196
"""
180197
table = pd.date_range(start="2020-01-01", periods=5).to_numpy()
181-
output = info(table=table, per_column=True)
198+
output = info(data=table, per_column=True)
182199
npt.assert_equal(
183200
actual=output, desired=["2020-01-01T00:00:00", "2020-01-05T00:00:00"]
184201
)
@@ -188,15 +205,15 @@ def test_info_spacing():
188205
"""
189206
Make sure the spacing option works.
190207
"""
191-
output = info(table=POINTS_DATA, spacing=0.1)
208+
output = info(data=POINTS_DATA, spacing=0.1)
192209
npt.assert_allclose(actual=output, desired=[11.5, 61.8, -3, 7.9])
193210

194211

195212
def test_info_spacing_bounding_box():
196213
"""
197214
Make sure the spacing option for writing a bounding box works.
198215
"""
199-
output = info(table=POINTS_DATA, spacing="b")
216+
output = info(data=POINTS_DATA, spacing="b")
200217
npt.assert_allclose(
201218
actual=output,
202219
desired=[
@@ -213,15 +230,15 @@ def test_info_per_column_spacing():
213230
"""
214231
Make sure the per_column and spacing options work together.
215232
"""
216-
output = info(table=POINTS_DATA, per_column=True, spacing=0.1)
233+
output = info(data=POINTS_DATA, per_column=True, spacing=0.1)
217234
npt.assert_allclose(actual=output, desired=[11.5, 61.8, -3, 7.9, 0.1412, 0.9338])
218235

219236

220237
def test_info_nearest_multiple():
221238
"""
222239
Make sure the nearest_multiple option works.
223240
"""
224-
output = info(table=POINTS_DATA, nearest_multiple=0.1)
241+
output = info(data=POINTS_DATA, nearest_multiple=0.1)
225242
npt.assert_allclose(actual=output, desired=[11.5, 61.8, 0.1])
226243

227244

@@ -231,4 +248,4 @@ def test_info_fails():
231248
DataFrame, or numpy ndarray.
232249
"""
233250
with pytest.raises(GMTInvalidInput):
234-
info(table=xr.DataArray(21))
251+
info(data=xr.DataArray(21))

0 commit comments

Comments
 (0)