Skip to content

Commit 61cf55d

Browse files
author
MomIsBestFriend
committed
Changed x.__class__ to type(x)
1 parent 6332b1e commit 61cf55d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+96
-102
lines changed

pandas/_libs/internals.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ cdef class BlockPlacement:
5454
else:
5555
v = self._as_array
5656

57-
return f'{self.__class__.__name__}({v})'
57+
return f'{type(self).__name__}({v})'
5858

5959
def __repr__(self) -> str:
6060
return str(self)

pandas/_libs/tslibs/offsets.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class _BaseOffset:
363363
attrs = [(k, v) for k, v in all_paras.items()
364364
if (k not in exclude) and (k[0] != '_')]
365365
attrs = sorted(set(attrs))
366-
params = tuple([str(self.__class__)] + attrs)
366+
params = tuple([str(type(self))] + attrs)
367367
return params
368368

369369
@property

pandas/core/arrays/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ def __repr__(self) -> str:
923923
data = format_object_summary(
924924
self, self._formatter(), indent_for_name=False
925925
).rstrip(", \n")
926-
class_name = "<{}>\n".format(self.__class__.__name__)
926+
class_name = "<{}>\n".format(type(self).__name__)
927927
return template.format(
928928
class_name=class_name, data=data, length=len(self), dtype=self.dtype
929929
)

pandas/core/arrays/interval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ def __repr__(self) -> str:
870870
# repr does. So we include a newline in our template, and strip
871871
# any trailing newlines from format_object_summary
872872
data = self._format_data()
873-
class_name = "<{}>\n".format(self.__class__.__name__)
873+
class_name = "<{}>\n".format(type(self).__name__)
874874
return template.format(
875875
class_name=class_name,
876876
data=data,
@@ -880,7 +880,7 @@ def __repr__(self) -> str:
880880
)
881881

882882
def _format_space(self):
883-
space = " " * (len(self.__class__.__name__) + 1)
883+
space = " " * (len(type(self).__name__) + 1)
884884
return "\n{space}".format(space=space)
885885

886886
@property

pandas/core/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class PandasObject(DirNamesMixin):
5151
@property
5252
def _constructor(self):
5353
"""class constructor (for this class it's just `__class__`"""
54-
return self.__class__
54+
return type(self)
5555

5656
def __repr__(self) -> str:
5757
"""
@@ -1185,7 +1185,7 @@ def _reduce(
11851185
if func is None:
11861186
raise TypeError(
11871187
"{klass} cannot perform the operation {op}".format(
1188-
klass=self.__class__.__name__, op=name
1188+
klass=type(self).__name__, op=name
11891189
)
11901190
)
11911191
return func(skipna=skipna, **kwds)

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def get_callable_name(obj):
317317
return get_callable_name(obj.func)
318318
# fall back to class name
319319
if hasattr(obj, "__call__"):
320-
return obj.__class__.__name__
320+
return type(obj).__name__
321321
# everything failed (probably because the argument
322322
# wasn't actually callable); we return None
323323
# instead of the empty string in this case to allow

pandas/core/computation/expr.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def visit(self, node, **kwargs):
435435
e.msg = "Python keyword not valid identifier in numexpr query"
436436
raise e
437437

438-
method = "visit_" + node.__class__.__name__
438+
method = "visit_" + type(node).__name__
439439
visitor = getattr(self, method)
440440
return visitor(node, **kwargs)
441441

pandas/core/computation/ops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def type(self):
145145
def raw(self) -> str:
146146
return pprint_thing(
147147
"{0}(name={1!r}, type={2})"
148-
"".format(self.__class__.__name__, self.name, self.type)
148+
"".format(type(self).__name__, self.name, self.type)
149149
)
150150

151151
@property

pandas/core/computation/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def visit_Attribute(self, node, **kwargs):
440440
attr = node.attr
441441
value = node.value
442442

443-
ctx = node.ctx.__class__
443+
ctx = type(node.ctx)
444444
if ctx == ast.Load:
445445
# resolve the value
446446
resolved = self.visit(value)

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def __repr__(self) -> str_type:
420420
if self.categories is None:
421421
data = "None, "
422422
else:
423-
data = self.categories._format_data(name=self.__class__.__name__)
423+
data = self.categories._format_data(name=type(self).__name__)
424424
return tpl.format(data=data, ordered=self._ordered)
425425

426426
@staticmethod

pandas/core/generic.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def _validate_dtype(self, dtype):
253253
if dtype.kind == "V":
254254
raise NotImplementedError(
255255
"compound dtypes are not implemented"
256-
" in the {0} constructor".format(self.__class__.__name__)
256+
" in the {0} constructor".format(type(self).__name__)
257257
)
258258

259259
return dtype
@@ -1536,7 +1536,7 @@ def __nonzero__(self):
15361536
raise ValueError(
15371537
"The truth value of a {0} is ambiguous. "
15381538
"Use a.empty, a.bool(), a.item(), a.any() or a.all().".format(
1539-
self.__class__.__name__
1539+
type(self).__name__
15401540
)
15411541
)
15421542

@@ -1561,7 +1561,7 @@ def bool(self):
15611561
elif is_scalar(v):
15621562
raise ValueError(
15631563
"bool cannot act on a non-boolean single element "
1564-
"{0}".format(self.__class__.__name__)
1564+
"{0}".format(type(self).__name__)
15651565
)
15661566

15671567
self.__nonzero__()
@@ -1867,7 +1867,7 @@ def _drop_labels_or_levels(self, keys, axis=0):
18671867
def __hash__(self):
18681868
raise TypeError(
18691869
"{0!r} objects are mutable, thus they cannot be"
1870-
" hashed".format(self.__class__.__name__)
1870+
" hashed".format(type(self).__name__)
18711871
)
18721872

18731873
def __iter__(self):
@@ -2061,7 +2061,7 @@ def __repr__(self) -> str:
20612061
# string representation based upon iterating over self
20622062
# (since, by definition, `PandasContainers` are iterable)
20632063
prepr = "[%s]" % ",".join(map(pprint_thing, self))
2064-
return f"{self.__class__.__name__}({prepr})"
2064+
return f"{type(self).__name__}({prepr})"
20652065

20662066
def _repr_latex_(self):
20672067
"""

pandas/core/groupby/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def _transform_general(self, func, *args, **kwargs):
473473
"""
474474
Transform with a non-str `func`.
475475
"""
476-
klass = self._selected_obj.__class__
476+
klass = type(self._selected_obj)
477477

478478
results = []
479479
for name, group in self:

pandas/core/groupby/grouper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def __repr__(self) -> str:
213213
if getattr(self, attr_name) is not None
214214
)
215215
attrs = ", ".join(attrs_list)
216-
cls_name = self.__class__.__name__
216+
cls_name = type(self).__name__
217217
return f"{cls_name}({attrs})"
218218

219219

pandas/core/indexes/base.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def take(self, indices, axis=0, allow_fill=True, fill_value=None, **kwargs):
826826
else:
827827
if allow_fill and fill_value is not None:
828828
msg = "Unable to fill values because {0} cannot contain NA"
829-
raise ValueError(msg.format(self.__class__.__name__))
829+
raise ValueError(msg.format(type(self).__name__))
830830
taken = self.values.take(indices)
831831
return self._shallow_copy(taken)
832832

@@ -959,7 +959,7 @@ def __repr__(self):
959959
"""
960960
Return a string representation for this object.
961961
"""
962-
klass = self.__class__.__name__
962+
klass = type(self).__name__
963963
data = self._format_data()
964964
attrs = self._format_attrs()
965965
space = self._format_space()
@@ -1311,7 +1311,7 @@ def _set_names(self, values, level=None):
13111311
for name in values:
13121312
if not is_hashable(name):
13131313
raise TypeError(
1314-
"{}.name must be a hashable type".format(self.__class__.__name__)
1314+
"{}.name must be a hashable type".format(type(self).__name__)
13151315
)
13161316
self.name = values[0]
13171317

@@ -1818,7 +1818,7 @@ def is_all_dates(self) -> bool:
18181818
def __reduce__(self):
18191819
d = dict(data=self._data)
18201820
d.update(self._get_attributes_dict())
1821-
return _new_Index, (self.__class__, d), None
1821+
return _new_Index, (type(self), d), None
18221822

18231823
def __setstate__(self, state):
18241824
"""
@@ -2314,7 +2314,7 @@ def __nonzero__(self):
23142314
raise ValueError(
23152315
"The truth value of a {0} is ambiguous. "
23162316
"Use a.empty, a.bool(), a.item(), a.any() or a.all().".format(
2317-
self.__class__.__name__
2317+
type(self).__name__
23182318
)
23192319
)
23202320

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def __reduce__(self):
423423

424424
d = dict(data=self._data)
425425
d.update(self._get_attributes_dict())
426-
return _new_DatetimeIndex, (self.__class__, d), None
426+
return _new_DatetimeIndex, (type(self), d), None
427427

428428
def __setstate__(self, state):
429429
"""Necessary for making this object picklable"""

pandas/core/indexes/frozen.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __mul__(self, other):
9090
__imul__ = __mul__
9191

9292
def __reduce__(self):
93-
return self.__class__, (list(self),)
93+
return type(self), (list(self),)
9494

9595
def __hash__(self):
9696
return hash(tuple(self))
@@ -99,15 +99,15 @@ def _disabled(self, *args, **kwargs):
9999
"""This method will not function because object is immutable."""
100100
raise TypeError(
101101
"'{cls}' does not support mutable operations.".format(
102-
cls=self.__class__.__name__
102+
cls=type(self).__name__
103103
)
104104
)
105105

106106
def __str__(self) -> str:
107107
return pprint_thing(self, quote_strings=True, escape_chars=("\t", "\r", "\n"))
108108

109109
def __repr__(self) -> str:
110-
return f"{self.__class__.__name__}({str(self)})"
110+
return f"{type(self).__name__}({str(self)})"
111111

112112
__setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled
113113
pop = append = extend = remove = sort = insert = _disabled
@@ -132,7 +132,7 @@ def __new__(cls, data, dtype=None, copy=False):
132132
def _disabled(self, *args, **kwargs):
133133
"""This method will not function because object is immutable."""
134134
raise TypeError(
135-
"'{cls}' does not support mutable operations.".format(cls=self.__class__)
135+
"'{cls}' does not support mutable operations.".format(cls=type(self))
136136
)
137137

138138
__setitem__ = __setslice__ = __delitem__ = __delslice__ = _disabled

pandas/core/indexes/interval.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ def __array_wrap__(self, result, context=None):
497497
def __reduce__(self):
498498
d = dict(left=self.left, right=self.right)
499499
d.update(self._get_attributes_dict())
500-
return _new_IntervalIndex, (self.__class__, d), None
500+
return _new_IntervalIndex, (type(self), d), None
501501

502502
@Appender(_index_shared_docs["copy"])
503503
def copy(self, deep=False, name=None):
@@ -512,7 +512,7 @@ def copy(self, deep=False, name=None):
512512

513513
@Appender(_index_shared_docs["astype"])
514514
def astype(self, dtype, copy=True):
515-
with rewrite_exception("IntervalArray", self.__class__.__name__):
515+
with rewrite_exception("IntervalArray", type(self).__name__):
516516
new_values = self.values.astype(dtype, copy=copy)
517517
if is_interval_dtype(new_values):
518518
return self._shallow_copy(new_values.left, new_values.right)
@@ -1205,7 +1205,7 @@ def _format_attrs(self):
12051205
return attrs
12061206

12071207
def _format_space(self):
1208-
space = " " * (len(self.__class__.__name__) + 1)
1208+
space = " " * (len(type(self).__name__) + 1)
12091209
return "\n{space}".format(space=space)
12101210

12111211
# --------------------------------------------------------------------

pandas/core/indexes/multi.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1274,9 +1274,7 @@ def _set_names(self, names, level=None, validate=True):
12741274
# All items in 'names' need to be hashable:
12751275
if not is_hashable(name):
12761276
raise TypeError(
1277-
"{}.name must be a hashable type".format(
1278-
self.__class__.__name__
1279-
)
1277+
"{}.name must be a hashable type".format(type(self).__name__)
12801278
)
12811279
self._names[lev] = name
12821280

@@ -1996,7 +1994,7 @@ def __reduce__(self):
19961994
sortorder=self.sortorder,
19971995
names=list(self.names),
19981996
)
1999-
return ibase._new_Index, (self.__class__, d), None
1997+
return ibase._new_Index, (type(self), d), None
20001998

20011999
def __setstate__(self, state):
20022000
"""Necessary for making this object picklable"""
@@ -3350,7 +3348,7 @@ def astype(self, dtype, copy=True):
33503348
elif not is_object_dtype(dtype):
33513349
msg = (
33523350
"Setting {cls} dtype to anything other than object is not supported"
3353-
).format(cls=self.__class__)
3351+
).format(cls=type(self))
33543352
raise TypeError(msg)
33553353
elif copy is True:
33563354
return self._shallow_copy()

pandas/core/indexes/range.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _get_data_as_items(self):
196196
def __reduce__(self):
197197
d = self._get_attributes_dict()
198198
d.update(dict(self._get_data_as_items()))
199-
return ibase._new_Index, (self.__class__, d), None
199+
return ibase._new_Index, (type(self), d), None
200200

201201
# --------------------------------------------------------------------
202202
# Rendering Methods

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def __len__(self) -> int:
319319
return len(self.items)
320320

321321
def __repr__(self) -> str:
322-
output = pprint_thing(self.__class__.__name__)
322+
output = pprint_thing(type(self).__name__)
323323
for i, ax in enumerate(self.axes):
324324
if i == 0:
325325
output += "\nItems: {ax}".format(ax=ax)

pandas/core/resample.py

+1-1
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):

pandas/core/series.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,7 @@ def __init__(
273273
elif is_extension_array_dtype(data):
274274
pass
275275
elif isinstance(data, (set, frozenset)):
276-
raise TypeError(
277-
"{0!r} type is unordered".format(data.__class__.__name__)
278-
)
276+
raise TypeError("{0!r} type is unordered".format(type(data).__name__))
279277
elif isinstance(data, ABCSparseArray):
280278
# handle sparse passed here (and force conversion)
281279
data = data.to_dense()
@@ -1590,7 +1588,7 @@ def to_string(
15901588
raise AssertionError(
15911589
"result must be of type unicode, type"
15921590
" of result is {0!r}"
1593-
"".format(result.__class__.__name__)
1591+
"".format(type(result).__name__)
15941592
)
15951593

15961594
if buf is None:

pandas/core/window/rolling.py

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

206206
@property
207207
def _window_type(self) -> str:
208-
return self.__class__.__name__
208+
return type(self).__name__
209209

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

0 commit comments

Comments
 (0)