Skip to content

Commit 5a37754

Browse files
committed
refactor
1 parent 5dd7294 commit 5a37754

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

pandas/core/generic.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5439,8 +5439,10 @@ def _dir_additions(self) -> Set[str]:
54395439
add the string-like attributes from the info_axis.
54405440
If info_axis is a MultiIndex, it's first level values are used.
54415441
"""
5442-
additions = self._info_axis._dir_additions_for_owner
5443-
return super()._dir_additions().union(additions)
5442+
additions = super()._dir_additions()
5443+
if self._info_axis._can_hold_strings:
5444+
additions &= self._info_axis._dir_additions_for_owner
5445+
return additions
54445446

54455447
# ----------------------------------------------------------------------
54465448
# Consolidation of internals

pandas/core/indexes/base.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -577,14 +577,11 @@ def _dir_additions_for_owner(self) -> Set[str_t]:
577577
578578
If this is a MultiIndex, it's first level values are used.
579579
"""
580-
if self._can_hold_strings:
581-
return {
582-
c
583-
for c in self.unique(level=0)[:100]
584-
if isinstance(c, str) and c.isidentifier()
585-
}
586-
else:
587-
return set()
580+
return {
581+
c
582+
for c in self.unique(level=0)[:100]
583+
if isinstance(c, str) and c.isidentifier()
584+
}
588585

589586
# --------------------------------------------------------------------
590587
# Array-Like Methods

0 commit comments

Comments
 (0)