Repository: yt-project/yt

Issue:
Make sure the docs use tuple field accesses
Following #3101 and #3194, ambiguous field accesses have been deprecated. We however have still many examples in the doc which use the old ambiguous syntax.

We should (gradually) update the doc to make sure no field accesses are ambiguous.


Discussion:
Is there a trivial way to make these actual failures as a way to catch them systematically in CI so we can fix them iteratively ?
What one can do is replace the depreciation warming with a hard error. A more efficient way would be to reimplements the mechanism I used for #3101 i.e. replace non tuple field accesses by the guessed tuple. That could possibly be excavated out of the above mentioned PR.

1 May 2021 12:44:04 Clément Robert ***@***.***>:

> Is there a trivial way to make these actual failures as a way to catch them systematically in CI so we can fix them iteratively ?
> 
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub[https://github.com/yt-project/yt/issues/3235#issuecomment-830619217], or unsubscribe[https://github.com/notifications/unsubscribe-auth/ABJJIIZWY7C6CRZV4N3XP2DTLPSQHANCNFSM432EDCKQ].
>  [data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABHNCSVQICAgIfAhkiAAAABxJREFUWIXtwQEBAAAAgiD/r25IQAEAAAAAAHwaGSgAAaRY3EgAAAAASUVORK5CYII=###24x24:true###][Tracking image][https://github.com/notifications/beacon/ABJJII2NPBVUUOQEXDIR5GTTLPSQHA5CNFSM432EDCK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOGGBD4UI.gif]
> 

I am trying to partially address this in #3284 
How much progress do you think you've accomplished in that PR @chummels ?
I think I got rid of all the non-tuple field accesses in the cookbook with that PR.  I'll continue to work on the docs, but I'm open to others helping.
@chummels @cphyc , I know you've both made large contributions to the docs regarding this lately. Do you think we can close this ?

Resolving patch:
diff --git a/yt/data_objects/static_output.py b/yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -918,15 +918,13 @@ def _are_ambiguous(candidates: List[Tuple[str, str]]) -> bool:
         if _are_ambiguous(candidates):
             ft, fn = field_info.name
             possible_ftypes = [c[0] for c in candidates]
-            msg = (
+            raise ValueError(
                 f"The requested field name {fn!r} "
                 "is ambiguous and corresponds to any one of "
                 f"the following field types:\n {possible_ftypes}\n"
                 "Please specify the requested field as an explicit "
                 "tuple (<ftype>, <fname>).\n"
-                f"Defaulting to {field_info.name!r}"
             )
-            issue_deprecation_warning(msg, since="4.0.0", removal="4.1.0")
         return field_info
 
     def _get_field_info_helper(self, ftype, fname=None):


Test patch:
diff --git a/yt/fields/tests/test_ambiguous_fields.py b/yt/fields/tests/test_ambiguous_fields.py
--- a/yt/fields/tests/test_ambiguous_fields.py
+++ b/yt/fields/tests/test_ambiguous_fields.py
@@ -1,6 +1,5 @@
 import pytest
 
-from yt._maintenance.deprecation import VisibleDeprecationWarning
 from yt.testing import fake_amr_ds
 
 
@@ -15,8 +14,8 @@ def _mock_field(field, data):
     ds.add_field(("io", "mock_field"), _mock_field, sampling_type="particle")
     ds.add_field(("gas", "mock_field"), _mock_field, sampling_type="cell")
 
-    # Test warnings are issued for ambiguous fields
-    with pytest.warns(VisibleDeprecationWarning, match=msg.format("mock_field")):
+    # Test errors are raised for ambiguous fields
+    with pytest.raises(ValueError, match=msg.format("mock_field")):
         ds.r["mock_field"]
 
     # check that explicit name tuples don't raise a warning