Repository: dask/dask
Pull request #7824 (2021-06-21 22:30:36)

Make `PY_VERSION` private
Starting in Python 3.7 modules can [define their own `__getattr__` function to implement custom logic when a module attribute is not found](https://docs.python.org/3/whatsnew/3.7.html#pep-562-customization-of-access-to-module-attributes). This provides a convenient mechanism for us to smoothly transition certain variables to be private (i.e. start with an underscore `_`). This PR demonstrates this approach with `dask.compatibility.PY_VERSION`, which isn't intended to be part of our public API and currently isn't used anywhere internally. 

xref https://github.com/dask/dask/pull/7820 where whether or not `PY_VERSION` is intended to be part of our public API came up


Patch:
diff --git a/dask/compatibility.py b/dask/compatibility.py
index 2777a6e18..8835b3321 100644
--- a/dask/compatibility.py
+++ b/dask/compatibility.py
@@ -12,4 +12,18 @@ except ImportError:
         return acc
 
 
-PY_VERSION = LooseVersion(".".join(map(str, sys.version_info[:3])))
+_PY_VERSION = LooseVersion(".".join(map(str, sys.version_info[:3])))
+
+
+def __getattr__(name):
+    if name == "PY_VERSION":
+        import warnings
+
+        warnings.warn(
+            "dask.compatibility.PY_VERSION is deprecated and will be removed "
+            "in a future release.",
+            category=FutureWarning,
+        )
+        return _PY_VERSION
+    else:
+        raise AttributeError(f"module {__name__} has no attribute {name}")
diff --git a/dask/layers.py b/dask/layers.py
index 97ed56f03..365df9a96 100644
--- a/dask/layers.py
+++ b/dask/layers.py
@@ -492,7 +492,7 @@ class SimpleShuffleLayer(DataFrameLayer):
         """
         parts_out = self._keys_to_parts(keys)
         culled_deps = self._cull_dependencies(keys, parts_out=parts_out)
-        if parts_out != self.parts_out:
+        if parts_out != set(self.parts_out):
             culled_layer = self._cull(parts_out)
             return culled_layer, culled_deps
         else:
diff --git a/docs/source/changelog.rst b/docs/source/changelog.rst
index 88a8f63a5..4e29e69ba 100644
--- a/docs/source/changelog.rst
+++ b/docs/source/changelog.rst
@@ -1,6 +1,16 @@
 Changelog
 =========
 
+2021.06.2
+---------
+
+Released on June 22, 2021
+
+- ``layers.py`` compare ``parts_out`` with ``set(self.parts_out)`` (:pr:`7787`) `Genevieve Buckley`_
+- Make ``check_meta`` understand pandas dtypes better (:pr:`7813`) `Julia Signell`_
+- Remove "Educational Resources" doc page (:pr:`7818`) `James Bourbeau`_
+
+
 2021.06.1
 ---------
 
diff --git a/setup.py b/setup.py
index 417511344..4703ec903 100755
--- a/setup.py
+++ b/setup.py
@@ -13,7 +13,7 @@ extras_require = {
     "array": ["numpy >= 1.16"],
     "bag": [],  # keeping for backwards compatibility
     "dataframe": ["numpy >= 1.16", "pandas >= 0.25.0"],
-    "distributed": ["distributed == 2021.06.1"],
+    "distributed": ["distributed == 2021.06.2"],
     "diagnostics": ["bokeh >= 1.0.0, != 2.0.0"],
     "delayed": [],  # keeping for backwards compatibility
 }


Test patch:
diff --git a/dask/tests/test_compatibility.py b/dask/tests/test_compatibility.py
new file mode 100644
index 000000000..6d79df3cb
--- /dev/null
+++ b/dask/tests/test_compatibility.py
@@ -0,0 +1,10 @@
+import pytest
+
+import dask
+
+
+def test_PY_VERSION_deprecated():
+
+    with pytest.warns(FutureWarning, match="removed in a future release"):
+        from dask.compatibility import PY_VERSION
+    assert PY_VERSION is dask.compatibility._PY_VERSION