Repository: modin-project/modin (python)

Issue:
BUG: Ambiguous error message when accessing missing attributes
### Modin version checks

- [x] I have checked that this issue has not already been reported.

- [x] I have confirmed this bug exists on the latest released version of Modin.

- [x] I have confirmed this bug exists on the main branch of Modin. (In order to do this you can follow [this guide](https://modin.readthedocs.io/en/stable/getting_started/installation.html#installing-from-the-github-main-branch).)


### Reproducible Example

```python
import modin.pandas as pd
pd.DataFrame().x
```

### Issue Description

The above example raises `AttributeError: 'super' object has no attribute '__getattr__'. Did you mean: '__setattr__'?`.

This occurs because of this line:
https://github.com/modin-project/modin/blob/f2002454c8b2db80fb372fb463643ff507711c19/modin/pandas/dataframe.py#L2651

`BasePandasDataset` does not define `__getattr__` (likely changed at some point in the past few PRs), so this code path should probably just check `key in self.columns` before raising a new `AttributeError`.

### Expected Behavior

Error message should match pandas more closely (in this case, `AttributeError: 'DataFrame' object has no attribute 'x'. Did you mean: 'xs'?`).

### Error Logs

<details>

```python-traceback

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/joshi/code/modin/modin/pandas/dataframe.py", line 2656, in __getattr__
    raise err
  File "/Users/joshi/code/modin/modin/pandas/dataframe.py", line 2652, in __getattr__
    return super().__getattr__(key)
           ^^^^^^^^^^^^^^^^^^^
AttributeError: 'super' object has no attribute '__getattr__'. Did you mean: '__setattr__'?
```

</details>


### Installed Versions

<details>

INSTALLED VERSIONS
------------------
commit                : f2002454c8b2db80fb372fb463643ff507711c19
python                : 3.11.11
python-bits           : 64
OS                    : Darwin
OS-release            : 24.5.0
Version               : Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:25 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6020
machine               : arm64
processor             : arm
byteorder             : little
LC_ALL                : None
LANG                  : en_US.UTF-8
LOCALE                : en_US.UTF-8

Modin dependencies
------------------
modin                 : 0.32.0+66.gf2002454.dirty
ray                   : 2.44.0
dask                  : 2025.3.0
distributed           : 2025.3.0

pandas dependencies
-------------------
pandas                : 2.2.3
numpy                 : 1.26.4
pytz                  : 2024.2
dateutil              : 2.9.0.post0
pip                   : 24.2
Cython                : None
sphinx                : 5.0.2
IPython               : 9.0.2
adbc-driver-postgresql: None
adbc-driver-sqlite    : None
bs4                   : 4.13.3
blosc                 : None
bottleneck            : None
dataframe-api-compat  : None
fastparquet           : None
fsspec                : 2024.12.0
html5lib              : None
hypothesis            : None
gcsfs                 : None
jinja2                : 3.1.5
lxml.etree            : 5.3.0
matplotlib            : 3.10.0
numba                 : None
numexpr               : None
odfpy                 : None
openpyxl              : 3.1.5
pandas_gbq            : None
psycopg2              : None
pymysql               : None
pyarrow               : 18.1.0
pyreadstat            : None
pytest                : 7.4.4
python-calamine       : None
pyxlsb                : None
s3fs                  : 2024.12.0
scipy                 : 1.15.1
sqlalchemy            : None
tables                : None
tabulate              : None
xarray                : None
xlrd                  : None
xlsxwriter            : None
zstandard             : None
tzdata                : 2024.2
qtpy                  : None
pyqt5                 : None
</details>


Pull request description:
FIX-#7576: Fix ambiguous AttributeError message
<!--
Thank you for your contribution!
Please review the contributing docs: https://modin.readthedocs.io/en/latest/development/contributing.html
if you have questions about contributing.
-->

## What do these changes do?

<!-- Please give a short brief about these changes. -->

- [x] first commit message and PR title follow format outlined [here](https://modin.readthedocs.io/en/latest/development/contributing.html#commit-message-formatting)
  > **_NOTE:_**  If you edit the PR title to match this format, you need to add another commit (even if it's empty) or amend your last commit for the CI job that checks the PR title to pick up the new PR title.
- [x] passes `flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py`
- [x] passes `black --check modin/ asv_bench/benchmarks scripts/doc_checker.py`
- [x] signed commit with `git commit -s` <!-- you can amend your commit with a signature via `git commit -amend -s` -->
- [x] Resolves #7576 <!-- issue must be created for each patch -->
- [x] tests added and passing
- [x] module layout described at `docs/development/architecture.rst` is up-to-date <!-- if you have added, renamed or removed files or directories please update the documentation accordingly -->


Patch:
diff --git a/modin/pandas/dataframe.py b/modin/pandas/dataframe.py
index c2df94d9..2c28796a 100644
--- a/modin/pandas/dataframe.py
+++ b/modin/pandas/dataframe.py
@@ -2647,12 +2647,9 @@ class DataFrame(BasePandasDataset):
         """
         # NOTE that to get an attribute, python calls __getattribute__() first and
         # then falls back to __getattr__() if the former raises an AttributeError.
-        try:
-            return super().__getattr__(key)
-        except AttributeError as err:
-            if key not in _ATTRS_NO_LOOKUP and key in self.columns:
-                return self[key]
-            raise err
+        if key not in _ATTRS_NO_LOOKUP and key in self.columns:
+            return self[key]
+        raise AttributeError(f"'DataFrame' object has no attribute '{key}'")
 
     def __setattr__(self, key, value) -> None:
         """
diff --git a/modin/pandas/series.py b/modin/pandas/series.py
index 01e61b62..94b27c54 100644
--- a/modin/pandas/series.py
+++ b/modin/pandas/series.py
@@ -390,12 +390,9 @@ class Series(BasePandasDataset):
         """
         # NOTE that to get an attribute, python calls __getattribute__() first and
         # then falls back to __getattr__() if the former raises an AttributeError.
-        try:
-            return super().__getattr__(key)
-        except AttributeError as err:
-            if key not in _ATTRS_NO_LOOKUP and key in self._query_compiler.index:
-                return self[key]
-            raise err
+        if key not in _ATTRS_NO_LOOKUP and key in self._query_compiler.index:
+            return self[key]
+        raise AttributeError(f"'Series' object has no attribute '{key}'")
 
     __float__ = _coerce_method(float)
     __int__ = _coerce_method(int)


Test patch:
diff --git a/modin/tests/pandas/extensions/test_dataframe_extensions.py b/modin/tests/pandas/extensions/test_dataframe_extensions.py
index fc6f7f6f..88ae0266 100644
--- a/modin/tests/pandas/extensions/test_dataframe_extensions.py
+++ b/modin/tests/pandas/extensions/test_dataframe_extensions.py
@@ -224,7 +224,10 @@ class TestProperty:
 
         df = pd.DataFrame({column_name: ["a"]}).set_backend(Backend1)
 
-        with pytest.raises(AttributeError):
+        with pytest.raises(
+            AttributeError,
+            match="'DataFrame' object has no attribute 'non_existent_column'",
+        ):
             getattr(df, "non_existent_column")
         column_getter.assert_called_once_with(df)