(
self,
data=None,
index: Axes | None = None,
columns: Axes | None = None,
dtype: Dtype | None = None,
copy: bool | None = None,
)
| 700 | # Constructors |
| 701 | |
| 702 | def __init__( |
| 703 | self, |
| 704 | data=None, |
| 705 | index: Axes | None = None, |
| 706 | columns: Axes | None = None, |
| 707 | dtype: Dtype | None = None, |
| 708 | copy: bool | None = None, |
| 709 | ) -> None: |
| 710 | allow_mgr = False |
| 711 | if dtype is not None: |
| 712 | dtype = self._validate_dtype(dtype) |
| 713 | |
| 714 | if isinstance(data, DataFrame): |
| 715 | data = data._mgr |
| 716 | allow_mgr = True |
| 717 | if not copy: |
| 718 | # if not copying data, ensure to still return a shallow copy |
| 719 | # to avoid the result sharing the same Manager |
| 720 | data = data.copy(deep=False) |
| 721 | |
| 722 | if isinstance(data, BlockManager): |
| 723 | if not allow_mgr: |
| 724 | # GH#52419 |
| 725 | warnings.warn( |
| 726 | f"Passing a {type(data).__name__} to {type(self).__name__} " |
| 727 | "is deprecated and will raise in a future version. " |
| 728 | "Use public APIs instead.", |
| 729 | Pandas4Warning, |
| 730 | stacklevel=2, |
| 731 | ) |
| 732 | |
| 733 | data = data.copy(deep=False) |
| 734 | # first check if a Manager is passed without any other arguments |
| 735 | # -> use fastpath (without checking Manager type) |
| 736 | if index is None and columns is None and dtype is None and not copy: |
| 737 | # GH#33357 fastpath |
| 738 | NDFrame.__init__(self, data) |
| 739 | return |
| 740 | |
| 741 | # GH47215 |
| 742 | if isinstance(index, set): |
| 743 | raise ValueError("index cannot be a set") |
| 744 | if isinstance(columns, set): |
| 745 | raise ValueError("columns cannot be a set") |
| 746 | |
| 747 | if copy is None: |
| 748 | if isinstance(data, dict): |
| 749 | # retain pre-GH#38939 default behavior |
| 750 | copy = True |
| 751 | elif not isinstance(data, (Index, DataFrame, Series)): |
| 752 | copy = True |
| 753 | else: |
| 754 | copy = False |
| 755 | |
| 756 | if data is None: |
| 757 | index = index if index is not None else default_index(0) |
| 758 | columns = columns if columns is not None else default_index(0) |
| 759 | dtype = dtype if dtype is not None else pandas_dtype(object) |
nothing calls this directly
no test coverage detected