Skip to content

Commit 77009b7

Browse files
author
MomIsBestFriend
committed
x.__class__ to type(x)
1 parent d338b94 commit 77009b7

File tree

9 files changed

+26
-30
lines changed

9 files changed

+26
-30
lines changed

pandas/core/indexing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class _NDFrameIndexer(_NDFrameIndexerBase):
105105

106106
def __call__(self, axis=None):
107107
# we need to return a copy of ourselves
108-
new_self = self.__class__(self.name, self.obj)
108+
new_self = type(self)(self.name, self.obj)
109109

110110
if axis is not None:
111111
axis = self.obj._get_axis_number(axis)

pandas/core/internals/blocks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ def make_block_same_class(self, values, placement=None, ndim=None):
257257
placement = self.mgr_locs
258258
if ndim is None:
259259
ndim = self.ndim
260-
return make_block(values, placement=placement, ndim=ndim, klass=self.__class__)
260+
return make_block(values, placement=placement, ndim=ndim, klass=type(self))
261261

262262
def __repr__(self) -> str:
263263
# don't want to print out all of the items here
264-
name = pprint_thing(self.__class__.__name__)
264+
name = pprint_thing(type(self).__name__)
265265
if self._is_single_block:
266266

267267
result = "{name}: {len} dtype: {dtype}".format(

pandas/core/internals/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(self, block, shape, indexers=None):
122122

123123
def __repr__(self) -> str:
124124
return "{name}({block!r}, {indexers})".format(
125-
name=self.__class__.__name__, block=self.block, indexers=self.indexers
125+
name=type(self).__name__, block=self.block, indexers=self.indexers
126126
)
127127

128128
@cache_readonly

pandas/core/internals/managers.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def make_empty(self, axes=None):
154154
blocks = np.array([], dtype=self.array_dtype)
155155
else:
156156
blocks = []
157-
return self.__class__(blocks, axes)
157+
return type(self)(blocks, axes)
158158

159159
def __nonzero__(self):
160160
return True
@@ -321,7 +321,7 @@ def __len__(self) -> int:
321321
return len(self.items)
322322

323323
def __repr__(self) -> str:
324-
output = pprint_thing(self.__class__.__name__)
324+
output = pprint_thing(type(self).__name__)
325325
for i, ax in enumerate(self.axes):
326326
if i == 0:
327327
output += "\nItems: {ax}".format(ax=ax)
@@ -435,7 +435,7 @@ def apply(
435435

436436
if len(result_blocks) == 0:
437437
return self.make_empty(axes or self.axes)
438-
bm = self.__class__(
438+
bm = type(self)(
439439
result_blocks, axes or self.axes, do_integrity_check=do_integrity_check
440440
)
441441
bm._consolidate_inplace()
@@ -524,7 +524,7 @@ def get_axe(block, qs, axes):
524524
for b in blocks
525525
]
526526

527-
return self.__class__(blocks, new_axes)
527+
return type(self)(blocks, new_axes)
528528

529529
# single block, i.e. ndim == {1}
530530
values = concat_compat([b.values for b in blocks])
@@ -634,7 +634,7 @@ def comp(s, regex=False):
634634
rb = new_rb
635635
result_blocks.extend(rb)
636636

637-
bm = self.__class__(result_blocks, self.axes)
637+
bm = type(self)(result_blocks, self.axes)
638638
bm._consolidate_inplace()
639639
return bm
640640

@@ -729,7 +729,7 @@ def combine(self, blocks, copy=True):
729729
axes = list(self.axes)
730730
axes[0] = self.items.take(indexer)
731731

732-
return self.__class__(new_blocks, axes, do_integrity_check=False)
732+
return type(self)(new_blocks, axes, do_integrity_check=False)
733733

734734
def get_slice(self, slobj, axis=0):
735735
if axis >= self.ndim:
@@ -746,7 +746,7 @@ def get_slice(self, slobj, axis=0):
746746
new_axes = list(self.axes)
747747
new_axes[axis] = new_axes[axis][slobj]
748748

749-
bm = self.__class__(new_blocks, new_axes, do_integrity_check=False)
749+
bm = type(self)(new_blocks, new_axes, do_integrity_check=False)
750750
bm._consolidate_inplace()
751751
return bm
752752

@@ -922,7 +922,7 @@ def consolidate(self):
922922
if self.is_consolidated():
923923
return self
924924

925-
bm = self.__class__(self.blocks, self.axes)
925+
bm = type(self)(self.blocks, self.axes)
926926
bm._is_consolidated = False
927927
bm._consolidate_inplace()
928928
return bm
@@ -1256,7 +1256,7 @@ def reindex_indexer(
12561256

12571257
new_axes = list(self.axes)
12581258
new_axes[axis] = new_axis
1259-
return self.__class__(new_blocks, new_axes)
1259+
return type(self)(new_blocks, new_axes)
12601260

12611261
def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None):
12621262
"""
@@ -1526,9 +1526,7 @@ def get_slice(self, slobj, axis=0):
15261526
if axis >= self.ndim:
15271527
raise IndexError("Requested axis not found in manager")
15281528

1529-
return self.__class__(
1530-
self._block._slice(slobj), self.index[slobj], fastpath=True
1531-
)
1529+
return type(self)(self._block._slice(slobj), self.index[slobj], fastpath=True)
15321530

15331531
@property
15341532
def index(self):

pandas/core/resample.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __str__(self) -> str:
9696
if getattr(self.groupby, k, None) is not None
9797
)
9898
return "{klass} [{attrs}]".format(
99-
klass=self.__class__.__name__, attrs=", ".join(attrs)
99+
klass=type(self).__name__, attrs=", ".join(attrs)
100100
)
101101

102102
def __getattr__(self, attr):
@@ -885,7 +885,7 @@ def count(self):
885885
result = self._downsample("count")
886886
if not len(self.ax):
887887
if self._selected_obj.ndim == 1:
888-
result = self._selected_obj.__class__(
888+
result = type(self._selected_obj)(
889889
[], index=result.index, dtype="int64", name=self._selected_obj.name
890890
)
891891
else:

pandas/core/series.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,7 @@ def __init__(
256256
elif is_extension_array_dtype(data):
257257
pass
258258
elif isinstance(data, (set, frozenset)):
259-
raise TypeError(
260-
"{0!r} type is unordered".format(data.__class__.__name__)
261-
)
259+
raise TypeError("{0!r} type is unordered".format(type(data).__name__))
262260
elif isinstance(data, ABCSparseArray):
263261
# handle sparse passed here (and force conversion)
264262
data = data.to_dense()
@@ -1573,7 +1571,7 @@ def to_string(
15731571
raise AssertionError(
15741572
"result must be of type unicode, type"
15751573
" of result is {0!r}"
1576-
"".format(result.__class__.__name__)
1574+
"".format(type(result).__name__)
15771575
)
15781576

15791577
if buf is None:

pandas/core/window/rolling.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _get_window(self, other=None, win_type: Optional[str] = None) -> int:
204204

205205
@property
206206
def _window_type(self) -> str:
207-
return self.__class__.__name__
207+
return type(self).__name__
208208

209209
def __repr__(self) -> str:
210210
"""

pandas/errors/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ def __str__(self) -> str:
178178
if self.methodtype == "classmethod":
179179
name = self.class_instance.__name__
180180
else:
181-
name = self.class_instance.__class__.__name__
181+
name = type(self.class_instance).__name__
182182
msg = "This {methodtype} must be defined in the concrete class {name}"
183183
return msg.format(methodtype=self.methodtype, name=name)

pandas/io/clipboard/__init__.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ def __init__(self, message):
9191
super().__init__(message)
9292

9393

94-
def _stringifyText(text) -> str:
94+
def _stringifyText(text):
9595
acceptedTypes = (str, int, float, bool)
9696
if not isinstance(text, acceptedTypes):
9797
raise PyperclipException(
9898
f"only str, int, float, and bool values"
99-
f"can be copied to the clipboard, not {text.__class__.__name__}"
99+
f"can be copied to the clipboard, not {type(text).__name__}"
100100
)
101101
return str(text)
102102

@@ -156,7 +156,7 @@ def copy_qt(text):
156156
cb = app.clipboard()
157157
cb.setText(text)
158158

159-
def paste_qt() -> str:
159+
def paste_qt():
160160
cb = app.clipboard()
161161
return str(cb.text())
162162

@@ -273,7 +273,7 @@ def copy_dev_clipboard(text):
273273
with open("/dev/clipboard", "wt") as fo:
274274
fo.write(text)
275275

276-
def paste_dev_clipboard() -> str:
276+
def paste_dev_clipboard():
277277
with open("/dev/clipboard", "rt") as fo:
278278
content = fo.read()
279279
return content
@@ -286,7 +286,7 @@ class ClipboardUnavailable:
286286
def __call__(self, *args, **kwargs):
287287
raise PyperclipException(EXCEPT_MSG)
288288

289-
def __bool__(self) -> bool:
289+
def __bool__(self):
290290
return False
291291

292292
return ClipboardUnavailable(), ClipboardUnavailable()
@@ -650,7 +650,7 @@ def lazy_load_stub_paste():
650650
return paste()
651651

652652

653-
def is_available() -> bool:
653+
def is_available():
654654
return copy != lazy_load_stub_copy and paste != lazy_load_stub_paste
655655

656656

0 commit comments

Comments
 (0)