Skip to content

Commit e3dd736

Browse files
authored
Apply suggestions from code review
1 parent 2f64ded commit e3dd736

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pandas/core/arrays/arrow/accessors.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ def __init__(self, data=None) -> None:
4040
def _validate(self, data):
4141
dtype = data.dtype
4242
if not isinstance(dtype, ArrowDtype):
43-
raise TypeError(self._validation_msg.format(dtype=dtype))
43+
# Raise AttributeError so that reflection handles non-struct Series correctly.
44+
raise AttributeError(self._validation_msg.format(dtype=dtype))
4445

4546
if not pa.types.is_struct(dtype.pyarrow_dtype):
46-
raise TypeError(self._validation_msg.format(dtype=dtype))
47+
# Raise AttributeError so that reflection handles non-struct Series correctly.
48+
raise AttributeError(self._validation_msg.format(dtype=dtype))
4749

4850
@property
4951
def dtypes(self) -> Series:

pandas/tests/series/accessors/test_struct_accessor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,5 @@ def test_struct_accessor_explode():
143143
def test_struct_accessor_api_for_invalid(invalid):
144144
msg = re.escape(StructAccessor._validation_msg.format(dtype=invalid.dtype))
145145

146-
with pytest.raises(TypeError, match=msg):
146+
with pytest.raises(AttributeError, match=msg):
147147
invalid.struct

0 commit comments

Comments
 (0)