Repository: regionmask/regionmask

Issue:
Deprecate `lon_name` and `lat_name`?
If the coords are named `"lon"` and `"lat"` we can do the following:

```python
region.mask(ds)
```

If they are named `"longitude"` and `"latitude"` we have two possibilities:

```python
region.mask(ds, lon_name="longitude", lat_name="latitude")  # (1)
region.mask(ds.longitude, ds.latitude)  # (2)
```

I don't think ~(2)~ (1) offers any advantage over ~(1)~ (2) - it's more verbose and harder to read (for me). Without (1) you can always do:

```python
region.mask(ds["longitude"], ds["latitude"])
region.mask(ds[lon_name], ds[lat_name])
```

What we loose is the possibility to set a custom name when numpy arrays are passed. I.e. the following is no longer possible:

```python
region.mask(ds.lon.values, ds.lat.values, lon_name="longitude", lat_name="latitude") 
```

But I don't think it's worth it - if you pass a numpy array you are unlikely wanting back a DataArray with a very specific naming (?). And the workaround would be relatively straightforward:

```python
mask = region.mask(ds.lon.values, ds.lat.values) 
mask = mask.rename(lat="latitude", lon="longitude")
```

This allows to remove two params from `mask` which is always a gain (IMHO). 





Discussion:
codecov-commenter: # [Codecov](https://codecov.io/gh/regionmask/regionmask/pull/371?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask) Report
> Merging [#371](https://codecov.io/gh/regionmask/regionmask/pull/371?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask) (69bcd15) into [main](https://codecov.io/gh/regionmask/regionmask/commit/38944bf41926c9164cc98af1d20dcc0c7fb0c179?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask) (38944bf) will **decrease** coverage by `0.06%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main     #371      +/-   ##
==========================================
- Coverage   98.54%   98.47%   -0.07%     
==========================================
  Files          16       16              
  Lines        1375     1379       +4     
==========================================
+ Hits         1355     1358       +3     
- Misses         20       21       +1     
```

| Flag | Coverage Δ | |
|---|---|---|
| bare-minimum | `91.57% <100.00%> (+0.02%)` | :arrow_up: |
| min-all-deps | `?` | |
| unittests | `98.47% <100.00%> (-0.07%)` | :arrow_down: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/regionmask/regionmask/pull/371?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask) | Coverage Δ | |
|---|---|---|
| [regionmask/core/\_geopandas.py](https://codecov.io/gh/regionmask/regionmask/pull/371/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask#diff-cmVnaW9ubWFzay9jb3JlL19nZW9wYW5kYXMucHk=) | `97.56% <ø> (ø)` | |
| [regionmask/core/regions.py](https://codecov.io/gh/regionmask/regionmask/pull/371/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask#diff-cmVnaW9ubWFzay9jb3JlL3JlZ2lvbnMucHk=) | `97.50% <ø> (ø)` | |
| [regionmask/core/mask.py](https://codecov.io/gh/regionmask/regionmask/pull/371/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask#diff-cmVnaW9ubWFzay9jb3JlL21hc2sucHk=) | `100.00% <100.00%> (ø)` | |
| [regionmask/defined\_regions/\_natural\_earth.py](https://codecov.io/gh/regionmask/regionmask/pull/371/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask#diff-cmVnaW9ubWFzay9kZWZpbmVkX3JlZ2lvbnMvX25hdHVyYWxfZWFydGgucHk=) | `96.20% <0.00%> (-0.48%)` | :arrow_down: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=regionmask)

mathause: If anyone has an opinion - feel free to voice it - I am slightly leaning towards deprecating this but can be convinced otherwise easily.

Patch:
diff --git a/docs/whats_new.rst b/docs/whats_new.rst
index 17b6bdd..516139d 100644
--- a/docs/whats_new.rst
+++ b/docs/whats_new.rst
@@ -32,6 +32,10 @@ Enhancements
 Deprecations
 ~~~~~~~~~~~~
 
+- Passing `lon_name` and `lat_name` to the masking methods and functions (e.g. :py:meth:`Regions.mask`)
+  is deprecated. Please pass the lon and lat coordinates direcly, e.g., `mask*(ds[lon_name], ds[lat_name])`
+  (:issue:`293` and :pull:`371`).
+
 New regions
 ~~~~~~~~~~~
 
diff --git a/regionmask/core/_geopandas.py b/regionmask/core/_geopandas.py
index b5104a1..6184956 100644
--- a/regionmask/core/_geopandas.py
+++ b/regionmask/core/_geopandas.py
@@ -218,8 +218,8 @@ def mask_geopandas(
     lon_or_obj,
     lat=None,
     *,
-    lon_name="lon",
-    lat_name="lat",
+    lon_name=None,
+    lat_name=None,
     numbers=None,
     method=None,
     wrap_lon=None,
@@ -252,8 +252,8 @@ def mask_3D_geopandas(
     lat=None,
     *,
     drop=True,
-    lon_name="lon",
-    lat_name="lat",
+    lon_name=None,
+    lat_name=None,
     numbers=None,
     method=None,
     wrap_lon=None,
diff --git a/regionmask/core/mask.py b/regionmask/core/mask.py
index 99c2092..aabc8ee 100644
--- a/regionmask/core/mask.py
+++ b/regionmask/core/mask.py
@@ -35,9 +35,9 @@ lat : array_like, optional
     If ``lon_or_obj`` is a longitude array, the latitude needs to be
     specified here.
 {drop_doc}lon_name : str, optional
-    Name of longitude in ``lon_or_obj``, default: "lon".
+    Deprecated. Name of longitude in ``lon_or_obj``, default: "lon".
 lat_name : str, optional
-    Name of latgitude in ``lon_or_obj``, default: "lat"
+    Deprecated. Name of latgitude in ``lon_or_obj``, default: "lat"
 {numbers_doc}method : "rasterize" | "shapely" | "pygeos". Default: None
     Method used to determine whether a gridpoint lies in a region.
     All methods lead to the same mask. If None (default)
@@ -137,8 +137,8 @@ def _mask(
     numbers,
     lon_or_obj,
     lat=None,
-    lon_name="lon",
-    lat_name="lat",
+    lon_name=None,
+    lat_name=None,
     method=None,
     wrap_lon=None,
     as_3D=False,
@@ -147,6 +147,16 @@ def _mask(
     internal function to create a mask
     """
 
+    if lon_name is not None or lat_name is not None:
+        warnings.warn(
+            "Passing 'lon_name' and 'lat_name' is deprecated. Please pass the lon and "
+            "lat coordinates direcly, e.g., `mask*(ds[lon_name], ds[lat_name])`.",
+            FutureWarning,
+        )
+
+    lon_name = "lon" if lon_name is None else lon_name
+    lat_name = "lat" if lat_name is None else lat_name
+
     if not _is_numeric(numbers):
         raise ValueError("'numbers' must be numeric")
 
@@ -235,8 +245,8 @@ def _mask_2D(
     numbers,
     lon_or_obj,
     lat=None,
-    lon_name="lon",
-    lat_name="lat",
+    lon_name=None,
+    lat_name=None,
     method=None,
     wrap_lon=None,
 ):
@@ -269,8 +279,8 @@ def _mask_3D(
     lon_or_obj,
     lat=None,
     drop=True,
-    lon_name="lon",
-    lat_name="lat",
+    lon_name=None,
+    lat_name=None,
     method=None,
     wrap_lon=None,
     as_3D=False,
diff --git a/regionmask/core/regions.py b/regionmask/core/regions.py
index 1a93c24..122a161 100644
--- a/regionmask/core/regions.py
+++ b/regionmask/core/regions.py
@@ -286,8 +286,8 @@ class Regions:
         lon_or_obj,
         lat=None,
         *,
-        lon_name="lon",
-        lat_name="lat",
+        lon_name=None,
+        lat_name=None,
         method=None,
         wrap_lon=None,
         flag="abbrevs",
@@ -342,8 +342,8 @@ class Regions:
         lat=None,
         *,
         drop=True,
-        lon_name="lon",
-        lat_name="lat",
+        lon_name=None,
+        lat_name=None,
         method=None,
         wrap_lon=None,
     ):


Test patch:
diff --git a/regionmask/tests/test_mask.py b/regionmask/tests/test_mask.py
index c478a0b..4650845 100644
--- a/regionmask/tests/test_mask.py
+++ b/regionmask/tests/test_mask.py
@@ -167,7 +167,12 @@ def test_mask_obj(lon_name, lat_name, method):
     expected = expected_mask_2D().rename(lat=lat_name, lon=lon_name)
 
     obj = {lon_name: dummy_ds.lon.values, lat_name: dummy_ds.lat.values}
-    result = dummy_region.mask(obj, method=method, lon_name=lon_name, lat_name=lat_name)
+    with pytest.warns(
+        FutureWarning, match="Passing 'lon_name' and 'lat_name' is deprecated"
+    ):
+        result = dummy_region.mask(
+            obj, method=method, lon_name=lon_name, lat_name=lat_name
+        )
 
     xr.testing.assert_equal(result, expected)
 
@@ -526,9 +531,12 @@ def test_mask_3D_obj(lon_name, lat_name, drop, method):
     expected = expected_mask_3D(drop).rename(lon=lon_name, lat=lat_name)
 
     obj = dummy_ds.rename(lon=lon_name, lat=lat_name)
-    result = dummy_region.mask_3D(
-        obj, method=method, drop=drop, lon_name=lon_name, lat_name=lat_name
-    )
+    with pytest.warns(
+        FutureWarning, match="Passing 'lon_name' and 'lat_name' is deprecated"
+    ):
+        result = dummy_region.mask_3D(
+            obj, method=method, drop=drop, lon_name=lon_name, lat_name=lat_name
+        )
 
     xr.testing.assert_equal(result, expected)