diff --git a/python/cudf/cudf/pandas/_wrappers/pandas.py b/python/cudf/cudf/pandas/_wrappers/pandas.py index 6d03063fa27..05e7d159c63 100644 --- a/python/cudf/cudf/pandas/_wrappers/pandas.py +++ b/python/cudf/cudf/pandas/_wrappers/pandas.py @@ -75,13 +75,27 @@ def _pandas_util_dir(): # In pandas 2.0, pandas.util contains public APIs under # __getattr__ but no __dir__ to find them # https://github.com/pandas-dev/pandas/blob/2.2.x/pandas/util/__init__.py - return list(importlib.import_module("pandas.util").__dict__.keys()) + [ - "hash_array", - "hash_pandas_object", - "Appender", - "Substitution", - "cache_readonly", - ] + res = list( + set( + list(importlib.import_module("pandas.util").__dict__.keys()) + + [ + "Appender", + "Substitution", + "_exceptions", + "_print_versions", + "cache_readonly", + "hash_array", + "hash_pandas_object", + "version", + "_tester", + "_validators", + "_decorators", + ] + ) + ) + if cudf.core._compat.PANDAS_GE_220: + res.append("capitalize_first_letter") + return res pd.util.__dir__ = _pandas_util_dir diff --git a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py index 7aefdc386bb..3e7d1cf3c4c 100644 --- a/python/cudf/cudf_pandas_tests/test_cudf_pandas.py +++ b/python/cudf/cudf_pandas_tests/test_cudf_pandas.py @@ -1759,3 +1759,21 @@ def test_fallback_raises_error(monkeypatch): monkeycontext.setenv("CUDF_PANDAS_FAIL_ON_FALLBACK", "True") with pytest.raises(ProxyFallbackError): pd.Series(range(2)).astype(object) + + +@pytest.mark.parametrize( + "attrs", + [ + "_exceptions", + "version", + "_print_versions", + "capitalize_first_letter", + "_validators", + "_decorators", + ], +) +def test_cudf_pandas_util_version(attrs): + if not PANDAS_GE_220 and attrs == "capitalize_first_letter": + assert not hasattr(pd.util, attrs) + else: + assert hasattr(pd.util, attrs)