Skip to content

Commit 3aec1d5

Browse files
authored
BUG: DataFrame.getattribute raising if columns have dtype string (pandas-dev#46301)
1 parent 2fdeb07 commit 3aec1d5

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

doc/source/whatsnew/v1.5.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ Indexing
394394
- Bug in :meth:`Series.mask` with ``inplace=True`` or setting values with a boolean mask with small integer dtypes incorrectly raising (:issue:`45750`)
395395
- Bug in :meth:`DataFrame.mask` with ``inplace=True`` and ``ExtensionDtype`` columns incorrectly raising (:issue:`45577`)
396396
- Bug in getting a column from a DataFrame with an object-dtype row index with datetime-like values: the resulting Series now preserves the exact object-dtype Index from the parent DataFrame (:issue:`42950`)
397+
- Bug in :meth:`DataFrame.__getattribute__` raising ``AttributeError`` if columns have ``"string"`` dtype (:issue:`46185`)
397398
- Bug in indexing on a :class:`DatetimeIndex` with a ``np.str_`` key incorrectly raising (:issue:`45580`)
398399
- Bug in :meth:`CategoricalIndex.get_indexer` when index contains ``NaN`` values, resulting in elements that are in target but not present in the index to be mapped to the index of the NaN element, instead of -1 (:issue:`45361`)
399400
- Bug in setting large integer values into :class:`Series` with ``float32`` or ``float16`` dtype incorrectly altering these values instead of coercing to ``float64`` dtype (:issue:`45844`)

pandas/core/indexes/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
is_object_dtype,
9898
is_scalar,
9999
is_signed_integer_dtype,
100+
is_string_dtype,
100101
is_unsigned_integer_dtype,
101102
needs_i8_conversion,
102103
pandas_dtype,
@@ -5276,7 +5277,7 @@ def _can_hold_identifiers_and_holds_name(self, name) -> bool:
52765277
52775278
https://github.com/pandas-dev/pandas/issues/19764
52785279
"""
5279-
if self.is_object() or self.is_categorical():
5280+
if self.is_object() or is_string_dtype(self.dtype) or self.is_categorical():
52805281
return name in self
52815282
return False
52825283

pandas/tests/frame/indexing/test_getitem.py

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ def test_getitem_sparse_column_return_type_and_dtype(self):
7272
result = df.loc[:, "A"]
7373
tm.assert_series_equal(result, expected)
7474

75+
def test_getitem_string_columns(self):
76+
# GH#46185
77+
df = DataFrame([[1, 2]], columns=Index(["A", "B"], dtype="string"))
78+
result = df.A
79+
expected = df["A"]
80+
tm.assert_series_equal(result, expected)
81+
7582

7683
class TestGetitemListLike:
7784
def test_getitem_list_missing_key(self):

0 commit comments

Comments
 (0)