Skip to content

Commit

Permalink
x.__class__ to type(x)
Browse files Browse the repository at this point in the history
  • Loading branch information
MomIsBestFriend committed Nov 27, 2019
1 parent d338b94 commit 77009b7
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 30 deletions.
2 changes: 1 addition & 1 deletion pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/window/rolling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 6 additions & 6 deletions pandas/io/clipboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 77009b7

Please sign in to comment.