Skip to content

Commit 6587876

Browse files
authored
Rename _GMT_DATASET.to_dataframe to .to_pandas and _GMT_GRID.to_dataarray/_GMT_IMAGE.to_dataarray to .to_xarray (#3798)
1 parent 4f80a70 commit 6587876

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

pygmt/clib/session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ def virtualfile_to_dataset(
22042204
if output_type == "strings": # strings output
22052205
return result.to_strings()
22062206

2207-
result = result.to_dataframe(
2207+
result = result.to_pandas(
22082208
header=header, column_names=column_names, dtype=dtype, index_col=index_col
22092209
)
22102210
if output_type == "numpy": # numpy.ndarray output
@@ -2273,7 +2273,7 @@ def virtualfile_to_raster(
22732273
self["GMT_IS_IMAGE"]: "image",
22742274
self["GMT_IS_CUBE"]: "cube",
22752275
}[family]
2276-
return self.read_virtualfile(vfname, kind=kind).contents.to_dataarray()
2276+
return self.read_virtualfile(vfname, kind=kind).contents.to_xarray()
22772277

22782278
def extract_region(self) -> np.ndarray:
22792279
"""

pygmt/datatypes/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def to_strings(self) -> np.ndarray[Any, np.dtype[np.str_]]:
172172
textvector = [item if item is not None else b"" for item in textvector]
173173
return np.char.decode(textvector) if textvector else np.array([], dtype=np.str_)
174174

175-
def to_dataframe(
175+
def to_pandas(
176176
self,
177177
header: int | None = None,
178178
column_names: pd.Index | None = None,
@@ -229,7 +229,7 @@ def to_dataframe(
229229
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
230230
... ds = lib.read_virtualfile(vouttbl, kind="dataset")
231231
... text = ds.contents.to_strings()
232-
... df = ds.contents.to_dataframe(header=0)
232+
... df = ds.contents.to_pandas(header=0)
233233
>>> text
234234
array(['TEXT1 TEXT23', 'TEXT4 TEXT567', 'TEXT8 TEXT90',
235235
'TEXT123 TEXT456789'], dtype='<U18')

pygmt/datatypes/grid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class _GMT_GRID(ctp.Structure): # noqa: N801
9595
("hidden", ctp.c_void_p),
9696
]
9797

98-
def to_dataarray(self) -> xr.DataArray:
98+
def to_xarray(self) -> xr.DataArray:
9999
"""
100100
Convert a _GMT_GRID object to a :class:`xarray.DataArray` object.
101101
@@ -113,7 +113,7 @@ def to_dataarray(self) -> xr.DataArray:
113113
... # Read the grid from the virtual file
114114
... grid = lib.read_virtualfile(voutgrd, kind="grid")
115115
... # Convert to xarray.DataArray and use it later
116-
... da = grid.contents.to_dataarray()
116+
... da = grid.contents.to_xarray()
117117
>>> da # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
118118
<xarray.DataArray 'z' (lat: 14, lon: 8)>...
119119
array([[347.5, 344.5, 386. , 640.5, 617. , 579. , 646.5, 671. ],

pygmt/datatypes/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class _GMT_IMAGE(ctp.Structure): # noqa: N801
9696
("hidden", ctp.c_void_p),
9797
]
9898

99-
def to_dataarray(self) -> xr.DataArray:
99+
def to_xarray(self) -> xr.DataArray:
100100
"""
101101
Convert a _GMT_IMAGE object to an :class:`xarray.DataArray` object.
102102
@@ -114,7 +114,7 @@ def to_dataarray(self) -> xr.DataArray:
114114
... # Read the image from the virtual file
115115
... image = lib.read_virtualfile(voutimg, kind="image")
116116
... # Convert to xarray.DataArray and use it later
117-
... da = image.contents.to_dataarray()
117+
... da = image.contents.to_xarray()
118118
>>> da # doctest: +NORMALIZE_WHITESPACE, +ELLIPSIS
119119
<xarray.DataArray 'z' (band: 3, y: 180, x: 360)>...
120120
array([[[ 10, 10, 10, ..., 10, 10, 10],

pygmt/tests/test_clib_read_data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_clib_read_data_dataset():
5959

6060
with Session() as lib:
6161
ds = lib.read_data(tmpfile.name, kind="dataset").contents
62-
df = ds.to_dataframe(header=0)
62+
df = ds.to_pandas(header=0)
6363
expected_df = pd.DataFrame(
6464
data={
6565
"x": [1.0, 4.0, 7.0, 10.0],
@@ -85,7 +85,7 @@ def test_clib_read_data_grid(expected_xrgrid):
8585
"""
8686
with Session() as lib:
8787
grid = lib.read_data("@static_earth_relief.nc", kind="grid").contents
88-
xrgrid = grid.to_dataarray()
88+
xrgrid = grid.to_xarray()
8989
xr.testing.assert_equal(xrgrid, expected_xrgrid)
9090
assert grid.header.contents.n_bands == 1 # Explicitly check n_bands
9191

@@ -113,7 +113,7 @@ def test_clib_read_data_grid_two_steps(expected_xrgrid):
113113
lib.read_data(infile, kind="grid", mode="GMT_DATA_ONLY", data=data_ptr)
114114

115115
# Full check
116-
xrgrid = data_ptr.contents.to_dataarray()
116+
xrgrid = data_ptr.contents.to_xarray()
117117
xr.testing.assert_equal(xrgrid, expected_xrgrid)
118118

119119

@@ -126,7 +126,7 @@ def test_clib_read_data_grid_actual_image(expected_xrimage):
126126
# Explicitly check n_bands. Only one band is read for 3-band images.
127127
assert image.header.contents.n_bands == 1
128128

129-
xrimage = image.to_dataarray()
129+
xrimage = image.to_xarray()
130130
assert xrimage.shape == (180, 360)
131131
assert xrimage.coords["x"].data.min() == -179.5
132132
assert xrimage.coords["x"].data.max() == 179.5
@@ -153,7 +153,7 @@ def test_clib_read_data_image(expected_xrimage):
153153
with Session() as lib:
154154
image = lib.read_data("@earth_day_01d", kind="image").contents
155155

156-
xrimage = image.to_dataarray()
156+
xrimage = image.to_xarray()
157157
assert xrimage.shape == (3, 180, 360)
158158
assert xrimage.coords["x"].data.min() == -179.5
159159
assert xrimage.coords["x"].data.max() == 179.5
@@ -187,7 +187,7 @@ def test_clib_read_data_image_two_steps(expected_xrimage):
187187
# Read the data
188188
lib.read_data(infile, kind="image", mode="GMT_DATA_ONLY", data=data_ptr)
189189

190-
xrimage = image.to_dataarray()
190+
xrimage = image.to_xarray()
191191
assert xrimage.shape == (3, 180, 360)
192192
assert xrimage.coords["x"].data.min() == -179.5
193193
assert xrimage.coords["x"].data.max() == 179.5

0 commit comments

Comments
 (0)