Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy as np

import pandas._libs.lib as lib
from pandas._typing import T
from pandas.compat import PYPY
from pandas.compat.numpy import function as nv
from pandas.errors import AbstractMethodError
Expand Down Expand Up @@ -87,6 +88,14 @@ def __sizeof__(self):
# object's 'sizeof'
return super().__sizeof__()

def _ensure_type(self: T, obj) -> T:
"""Ensure that an object has same type as self.

Used by type checkers.
"""
assert isinstance(obj, type(self)), type(obj)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line breaks any code that creates a subclass of the pandas.core.frame.DataFrame. issubclass should be used instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, see also #31925 (maybe repeat your comment there). We should fix this for 1.0.2

return obj


class NoNewAttributesMixin:
"""Mixin which prevents adding new attributes.
Expand Down
Loading