diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index b52015b738c6e..1f5783436813e 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -105,7 +105,7 @@ class _NDFrameIndexer(_NDFrameIndexerBase): def __call__(self, axis=None): # we need to return a copy of ourselves - new_self = self.__class__(self.name, self.obj) + new_self = type(self)(self.name, self.obj) if axis is not None: axis = self.obj._get_axis_number(axis) diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 2d6ffb7277742..5fac8cea67bab 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -257,11 +257,11 @@ def make_block_same_class(self, values, placement=None, ndim=None): placement = self.mgr_locs if ndim is None: ndim = self.ndim - return make_block(values, placement=placement, ndim=ndim, klass=self.__class__) + return make_block(values, placement=placement, ndim=ndim, klass=type(self)) def __repr__(self) -> str: # don't want to print out all of the items here - name = pprint_thing(self.__class__.__name__) + name = pprint_thing(type(self).__name__) if self._is_single_block: result = "{name}: {len} dtype: {dtype}".format( diff --git a/pandas/core/internals/concat.py b/pandas/core/internals/concat.py index f981c00fdad36..6c4ab2882d67f 100644 --- a/pandas/core/internals/concat.py +++ b/pandas/core/internals/concat.py @@ -122,7 +122,7 @@ def __init__(self, block, shape, indexers=None): def __repr__(self) -> str: return "{name}({block!r}, {indexers})".format( - name=self.__class__.__name__, block=self.block, indexers=self.indexers + name=type(self).__name__, block=self.block, indexers=self.indexers ) @cache_readonly diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index c37a8ea5e42a4..4dc2cac0ad534 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -154,7 +154,7 @@ def make_empty(self, axes=None): blocks = np.array([], dtype=self.array_dtype) else: blocks = [] - return self.__class__(blocks, axes) + return type(self)(blocks, axes) def __nonzero__(self): return True @@ -321,7 +321,7 @@ def __len__(self) -> int: return len(self.items) def __repr__(self) -> str: - output = pprint_thing(self.__class__.__name__) + output = pprint_thing(type(self).__name__) for i, ax in enumerate(self.axes): if i == 0: output += "\nItems: {ax}".format(ax=ax) @@ -435,7 +435,7 @@ def apply( if len(result_blocks) == 0: return self.make_empty(axes or self.axes) - bm = self.__class__( + bm = type(self)( result_blocks, axes or self.axes, do_integrity_check=do_integrity_check ) bm._consolidate_inplace() @@ -524,7 +524,7 @@ def get_axe(block, qs, axes): for b in blocks ] - return self.__class__(blocks, new_axes) + return type(self)(blocks, new_axes) # single block, i.e. ndim == {1} values = concat_compat([b.values for b in blocks]) @@ -634,7 +634,7 @@ def comp(s, regex=False): rb = new_rb result_blocks.extend(rb) - bm = self.__class__(result_blocks, self.axes) + bm = type(self)(result_blocks, self.axes) bm._consolidate_inplace() return bm @@ -729,7 +729,7 @@ def combine(self, blocks, copy=True): axes = list(self.axes) axes[0] = self.items.take(indexer) - return self.__class__(new_blocks, axes, do_integrity_check=False) + return type(self)(new_blocks, axes, do_integrity_check=False) def get_slice(self, slobj, axis=0): if axis >= self.ndim: @@ -746,7 +746,7 @@ def get_slice(self, slobj, axis=0): new_axes = list(self.axes) new_axes[axis] = new_axes[axis][slobj] - bm = self.__class__(new_blocks, new_axes, do_integrity_check=False) + bm = type(self)(new_blocks, new_axes, do_integrity_check=False) bm._consolidate_inplace() return bm @@ -922,7 +922,7 @@ def consolidate(self): if self.is_consolidated(): return self - bm = self.__class__(self.blocks, self.axes) + bm = type(self)(self.blocks, self.axes) bm._is_consolidated = False bm._consolidate_inplace() return bm @@ -1256,7 +1256,7 @@ def reindex_indexer( new_axes = list(self.axes) new_axes[axis] = new_axis - return self.__class__(new_blocks, new_axes) + return type(self)(new_blocks, new_axes) def _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple=None): """ @@ -1526,9 +1526,7 @@ def get_slice(self, slobj, axis=0): if axis >= self.ndim: raise IndexError("Requested axis not found in manager") - return self.__class__( - self._block._slice(slobj), self.index[slobj], fastpath=True - ) + return type(self)(self._block._slice(slobj), self.index[slobj], fastpath=True) @property def index(self): diff --git a/pandas/core/resample.py b/pandas/core/resample.py index 2433e3f52b4a9..58c4a97d651d8 100644 --- a/pandas/core/resample.py +++ b/pandas/core/resample.py @@ -96,7 +96,7 @@ def __str__(self) -> str: if getattr(self.groupby, k, None) is not None ) return "{klass} [{attrs}]".format( - klass=self.__class__.__name__, attrs=", ".join(attrs) + klass=type(self).__name__, attrs=", ".join(attrs) ) def __getattr__(self, attr): @@ -885,7 +885,7 @@ def count(self): result = self._downsample("count") if not len(self.ax): if self._selected_obj.ndim == 1: - result = self._selected_obj.__class__( + result = type(self._selected_obj)( [], index=result.index, dtype="int64", name=self._selected_obj.name ) else: diff --git a/pandas/core/series.py b/pandas/core/series.py index a9ecf97dad68b..cfcd5577e9ee0 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -256,9 +256,7 @@ def __init__( elif is_extension_array_dtype(data): pass elif isinstance(data, (set, frozenset)): - raise TypeError( - "{0!r} type is unordered".format(data.__class__.__name__) - ) + raise TypeError("{0!r} type is unordered".format(type(data).__name__)) elif isinstance(data, ABCSparseArray): # handle sparse passed here (and force conversion) data = data.to_dense() @@ -1573,7 +1571,7 @@ def to_string( raise AssertionError( "result must be of type unicode, type" " of result is {0!r}" - "".format(result.__class__.__name__) + "".format(type(result).__name__) ) if buf is None: diff --git a/pandas/core/window/rolling.py b/pandas/core/window/rolling.py index 7f3404100f71c..d8aa362080093 100644 --- a/pandas/core/window/rolling.py +++ b/pandas/core/window/rolling.py @@ -204,7 +204,7 @@ def _get_window(self, other=None, win_type: Optional[str] = None) -> int: @property def _window_type(self) -> str: - return self.__class__.__name__ + return type(self).__name__ def __repr__(self) -> str: """ diff --git a/pandas/errors/__init__.py b/pandas/errors/__init__.py index 73cc40ae0e0d3..34838af5fd6e4 100644 --- a/pandas/errors/__init__.py +++ b/pandas/errors/__init__.py @@ -178,6 +178,6 @@ def __str__(self) -> str: if self.methodtype == "classmethod": name = self.class_instance.__name__ else: - name = self.class_instance.__class__.__name__ + name = type(self.class_instance).__name__ msg = "This {methodtype} must be defined in the concrete class {name}" return msg.format(methodtype=self.methodtype, name=name) diff --git a/pandas/io/clipboard/__init__.py b/pandas/io/clipboard/__init__.py index 7d3dbaf6ee021..6e560dc7b43eb 100644 --- a/pandas/io/clipboard/__init__.py +++ b/pandas/io/clipboard/__init__.py @@ -91,12 +91,12 @@ def __init__(self, message): super().__init__(message) -def _stringifyText(text) -> str: +def _stringifyText(text): acceptedTypes = (str, int, float, bool) if not isinstance(text, acceptedTypes): raise PyperclipException( f"only str, int, float, and bool values" - f"can be copied to the clipboard, not {text.__class__.__name__}" + f"can be copied to the clipboard, not {type(text).__name__}" ) return str(text) @@ -156,7 +156,7 @@ def copy_qt(text): cb = app.clipboard() cb.setText(text) - def paste_qt() -> str: + def paste_qt(): cb = app.clipboard() return str(cb.text()) @@ -273,7 +273,7 @@ def copy_dev_clipboard(text): with open("/dev/clipboard", "wt") as fo: fo.write(text) - def paste_dev_clipboard() -> str: + def paste_dev_clipboard(): with open("/dev/clipboard", "rt") as fo: content = fo.read() return content @@ -286,7 +286,7 @@ class ClipboardUnavailable: def __call__(self, *args, **kwargs): raise PyperclipException(EXCEPT_MSG) - def __bool__(self) -> bool: + def __bool__(self): return False return ClipboardUnavailable(), ClipboardUnavailable() @@ -650,7 +650,7 @@ def lazy_load_stub_paste(): return paste() -def is_available() -> bool: +def is_available(): return copy != lazy_load_stub_copy and paste != lazy_load_stub_paste