diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 866b58c1ffe3d..1b9cddab0df29 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1,3 +1,4 @@ +import builtins import collections from datetime import timedelta import functools @@ -154,9 +155,6 @@ def _single_replace(self, to_replace, method, inplace, limit): return result -bool_t = bool # Need alias because NDFrame has def bool: - - class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin): """ N-dimensional analogue of DataFrame. Store multi-dimensional in a @@ -1439,7 +1437,7 @@ def _is_level_reference(self, key, axis=0): and not self._is_label_reference(key, axis=axis) ) - def _is_label_reference(self, key, axis=0) -> bool_t: + def _is_label_reference(self, key, axis=0) -> builtins.bool: """ Test whether a key is a label reference for a given axis. @@ -1468,7 +1466,7 @@ def _is_label_reference(self, key, axis=0) -> bool_t: and any(key in self.axes[ax] for ax in other_axes) ) - def _is_label_or_level_reference(self, key: str, axis: int = 0) -> bool_t: + def _is_label_or_level_reference(self, key: str, axis: int = 0) -> builtins.bool: """ Test whether a key is a label or level reference for a given axis. @@ -1734,12 +1732,12 @@ def __len__(self) -> int: """Returns length of info axis""" return len(self._info_axis) - def __contains__(self, key) -> bool_t: + def __contains__(self, key) -> builtins.bool: """True if the key is in the info axis""" return key in self._info_axis @property - def empty(self) -> bool_t: + def empty(self) -> builtins.bool: """ Indicator whether DataFrame is empty. @@ -2075,12 +2073,12 @@ def to_json( orient: Optional[str] = None, date_format: Optional[str] = None, double_precision: int = 10, - force_ascii: bool_t = True, + force_ascii: builtins.bool = True, date_unit: str = "ms", default_handler: Optional[Callable[[Any], JSONSerializable]] = None, - lines: bool_t = False, + lines: builtins.bool = False, compression: Optional[str] = "infer", - index: bool_t = True, + index: builtins.bool = True, indent: Optional[int] = None, ) -> Optional[str]: """ @@ -2257,12 +2255,12 @@ def to_hdf( mode: str = "a", complevel: Optional[int] = None, complib: Optional[str] = None, - append: bool_t = False, + append: builtins.bool = False, format: Optional[str] = None, - index: bool_t = True, + index: builtins.bool = True, min_itemsize: Optional[Union[int, Dict[str, int]]] = None, nan_rep=None, - dropna: Optional[bool_t] = None, + dropna: Optional[builtins.bool] = None, data_columns: Optional[List[str]] = None, errors: str = "strict", encoding: str = "UTF-8", @@ -2397,7 +2395,7 @@ def to_sql( con, schema=None, if_exists: str = "fail", - index: bool_t = True, + index: builtins.bool = True, index_label=None, chunksize=None, dtype=None, @@ -2610,7 +2608,7 @@ def to_pickle( to_pickle(self, path, compression=compression, protocol=protocol) def to_clipboard( - self, excel: bool_t = True, sep: Optional[str] = None, **kwargs + self, excel: builtins.bool = True, sep: Optional[str] = None, **kwargs ) -> None: r""" Copy object to the system clipboard. @@ -2931,9 +2929,9 @@ def to_csv( na_rep: str = "", float_format: Optional[str] = None, columns: Optional[Sequence[Label]] = None, - header: Union[bool_t, List[str]] = True, - index: bool_t = True, - index_label: Optional[Union[bool_t, str, Sequence[Label]]] = None, + header: Union[builtins.bool, List[str]] = True, + index: builtins.bool = True, + index_label: Optional[Union[builtins.bool, str, Sequence[Label]]] = None, mode: str = "w", encoding: Optional[str] = None, compression: Optional[Union[str, Mapping[str, str]]] = "infer", @@ -2942,7 +2940,7 @@ def to_csv( line_terminator: Optional[str] = None, chunksize: Optional[int] = None, date_format: Optional[str] = None, - doublequote: bool_t = True, + doublequote: builtins.bool = True, escapechar: Optional[str] = None, decimal: Optional[str] = ".", ) -> Optional[str]: @@ -3116,7 +3114,7 @@ def _maybe_cache_changed(self, item, value) -> None: self._data.set(item, value) @property - def _is_cached(self) -> bool_t: + def _is_cached(self) -> builtins.bool: """Return boolean indicating if self is cached or not.""" return getattr(self, "_cacher", None) is not None @@ -3128,7 +3126,7 @@ def _get_cacher(self): return cacher def _maybe_update_cacher( - self, clear: bool_t = False, verify_is_copy: bool_t = True + self, clear: builtins.bool = False, verify_is_copy: builtins.bool = True ) -> None: """ See if we need to update our parent cacher if clear, then clear our @@ -3172,7 +3170,11 @@ def _clear_item_cache(self) -> None: # Indexing Methods def take( - self: FrameOrSeries, indices, axis=0, is_copy: Optional[bool_t] = None, **kwargs + self: FrameOrSeries, + indices, + axis=0, + is_copy: Optional[builtins.bool] = None, + **kwargs, ) -> FrameOrSeries: """ Return the elements in the given *positional* indices along an axis. @@ -3284,7 +3286,7 @@ def _take_with_is_copy(self: FrameOrSeries, indices, axis=0) -> FrameOrSeries: result._set_is_copy(self) return result - def xs(self, key, axis=0, level=None, drop_level: bool_t = True): + def xs(self, key, axis=0, level=None, drop_level: builtins.bool = True): """ Return cross-section from the Series/DataFrame. @@ -3487,14 +3489,14 @@ def _set_item(self, key, value) -> None: self._data.set(key, value) self._clear_item_cache() - def _set_is_copy(self, ref, copy: bool_t = True) -> None: + def _set_is_copy(self, ref, copy: builtins.bool = True) -> None: if not copy: self._is_copy = None else: assert ref is not None self._is_copy = weakref.ref(ref) - def _check_is_chained_assignment_possible(self) -> bool_t: + def _check_is_chained_assignment_possible(self) -> builtins.bool: """ Check if we are a view, have a cacher, and are of mixed type. If so, then force a setitem_copy check. @@ -3647,7 +3649,7 @@ def get(self, key, default=None): return default @property - def _is_view(self) -> bool_t: + def _is_view(self) -> builtins.bool: """Return boolean indicating if self is view of another array """ return self._data.is_view @@ -3655,7 +3657,7 @@ def reindex_like( self: FrameOrSeries, other, method: Optional[str] = None, - copy: bool_t = True, + copy: builtins.bool = True, limit=None, tolerance=None, ) -> FrameOrSeries: @@ -3771,7 +3773,7 @@ def drop( index=None, columns=None, level=None, - inplace: bool_t = False, + inplace: builtins.bool = False, errors: str = "raise", ): @@ -3855,7 +3857,7 @@ def _drop_axis( return result - def _update_inplace(self, result, verify_is_copy: bool_t = True) -> None: + def _update_inplace(self, result, verify_is_copy: builtins.bool = True) -> None: """ Replace self internals with result. @@ -3994,10 +3996,10 @@ def sort_values( self, axis=0, ascending=True, - inplace: bool_t = False, + inplace: builtins.bool = False, kind: str = "quicksort", na_position: str = "last", - ignore_index: bool_t = False, + ignore_index: builtins.bool = False, ): """ Sort by the values along either axis. @@ -4364,7 +4366,7 @@ def _reindex_axes( return obj - def _needs_reindex_multi(self, axes, method, level) -> bool_t: + def _needs_reindex_multi(self, axes, method, level) -> builtins.bool: """Check if we do need a multi reindex.""" return ( (com.count_not_none(*axes.values()) == self._AXIS_LEN) @@ -4380,8 +4382,8 @@ def _reindex_with_indexers( self: FrameOrSeries, reindexers, fill_value=None, - copy: bool_t = False, - allow_dups: bool_t = False, + copy: builtins.bool = False, + allow_dups: builtins.bool = False, ) -> FrameOrSeries: """allow_dups indicates an internal call here """ # reindex doing multiple operations on different axes if indicated @@ -5142,7 +5144,7 @@ def f(): self._protect_consolidate(f) - def _consolidate(self, inplace: bool_t = False): + def _consolidate(self, inplace: builtins.bool = False): """ Compute NDFrame with "consolidated" internals (data of each dtype grouped together in a single ndarray). @@ -5165,16 +5167,16 @@ def _consolidate(self, inplace: bool_t = False): return self._constructor(cons_data).__finalize__(self) @property - def _is_mixed_type(self) -> bool_t: + def _is_mixed_type(self) -> builtins.bool: f = lambda: self._data.is_mixed_type return self._protect_consolidate(f) @property - def _is_numeric_mixed_type(self) -> bool_t: + def _is_numeric_mixed_type(self) -> builtins.bool: f = lambda: self._data.is_numeric_mixed_type return self._protect_consolidate(f) - def _check_inplace_setting(self, value) -> bool_t: + def _check_inplace_setting(self, value) -> builtins.bool: """ check whether we allow in-place setting with this type of value """ if self._is_mixed_type: if not self._is_numeric_mixed_type: @@ -5333,7 +5335,7 @@ def dtypes(self): return Series(self._data.get_dtypes(), index=self._info_axis, dtype=np.object_) - def _to_dict_of_blocks(self, copy: bool_t = True): + def _to_dict_of_blocks(self, copy: builtins.bool = True): """ Return a dict of dtype -> Constructor Types that each is a homogeneous dtype. @@ -5346,7 +5348,7 @@ def _to_dict_of_blocks(self, copy: bool_t = True): } def astype( - self: FrameOrSeries, dtype, copy: bool_t = True, errors: str = "raise" + self: FrameOrSeries, dtype, copy: builtins.bool = True, errors: str = "raise" ) -> FrameOrSeries: """ Cast a pandas object to a specified dtype ``dtype``. @@ -5488,7 +5490,7 @@ def astype( result.columns = self.columns return result - def copy(self: FrameOrSeries, deep: bool_t = True) -> FrameOrSeries: + def copy(self: FrameOrSeries, deep: builtins.bool = True) -> FrameOrSeries: """ Make a copy of this object's indices and data. @@ -5596,7 +5598,7 @@ def copy(self: FrameOrSeries, deep: bool_t = True) -> FrameOrSeries: data = self._data.copy(deep=deep) return self._constructor(data).__finalize__(self) - def __copy__(self: FrameOrSeries, deep: bool_t = True) -> FrameOrSeries: + def __copy__(self: FrameOrSeries, deep: builtins.bool = True) -> FrameOrSeries: return self.copy(deep=deep) def __deepcopy__(self: FrameOrSeries, memo=None) -> FrameOrSeries: @@ -5610,11 +5612,11 @@ def __deepcopy__(self: FrameOrSeries, memo=None) -> FrameOrSeries: def _convert( self: FrameOrSeries, - datetime: bool_t = False, - numeric: bool_t = False, - timedelta: bool_t = False, - coerce: bool_t = False, - copy: bool_t = True, + datetime: builtins.bool = False, + numeric: builtins.bool = False, + timedelta: builtins.bool = False, + coerce: builtins.bool = False, + copy: builtins.bool = True, ) -> FrameOrSeries: """ Attempt to infer better dtype for object columns @@ -5706,10 +5708,10 @@ def infer_objects(self: FrameOrSeries) -> FrameOrSeries: def convert_dtypes( self: FrameOrSeries, - infer_objects: bool_t = True, - convert_string: bool_t = True, - convert_integer: bool_t = True, - convert_boolean: bool_t = True, + infer_objects: builtins.bool = True, + convert_string: builtins.bool = True, + convert_integer: builtins.bool = True, + convert_boolean: builtins.bool = True, ) -> FrameOrSeries: """ Convert columns to best possible dtypes using dtypes supporting ``pd.NA``. @@ -5848,7 +5850,7 @@ def fillna( value=None, method=None, axis=None, - inplace: bool_t = False, + inplace: builtins.bool = False, limit=None, downcast=None, ) -> Optional[FrameOrSeries]: @@ -6035,7 +6037,7 @@ def fillna( def ffill( self: FrameOrSeries, axis=None, - inplace: bool_t = False, + inplace: builtins.bool = False, limit=None, downcast=None, ) -> Optional[FrameOrSeries]: @@ -6054,7 +6056,7 @@ def ffill( def bfill( self: FrameOrSeries, axis=None, - inplace: bool_t = False, + inplace: builtins.bool = False, limit=None, downcast=None, ) -> Optional[FrameOrSeries]: @@ -7138,7 +7140,7 @@ def notna(self: FrameOrSeries) -> FrameOrSeries: def notnull(self: FrameOrSeries) -> FrameOrSeries: return notna(self).__finalize__(self) - def _clip_with_scalar(self, lower, upper, inplace: bool_t = False): + def _clip_with_scalar(self, lower, upper, inplace: builtins.bool = False): if (lower is not None and np.any(isna(lower))) or ( upper is not None and np.any(isna(upper)) ): @@ -7191,7 +7193,7 @@ def clip( lower=None, upper=None, axis=None, - inplace: bool_t = False, + inplace: builtins.bool = False, *args, **kwargs, ) -> FrameOrSeries: @@ -7375,7 +7377,7 @@ def asfreq( freq, method=None, how: Optional[str] = None, - normalize: bool_t = False, + normalize: builtins.bool = False, fill_value=None, ) -> FrameOrSeries: """ @@ -7480,7 +7482,7 @@ def asfreq( ) def at_time( - self: FrameOrSeries, time, asof: bool_t = False, axis=None + self: FrameOrSeries, time, asof: builtins.bool = False, axis=None ) -> FrameOrSeries: """ Select values at particular time of day (e.g., 9:30AM). @@ -7541,8 +7543,8 @@ def between_time( self: FrameOrSeries, start_time, end_time, - include_start: bool_t = True, - include_end: bool_t = True, + include_start: builtins.bool = True, + include_end: builtins.bool = True, axis=None, ) -> FrameOrSeries: """ @@ -8040,10 +8042,10 @@ def rank( self: FrameOrSeries, axis=0, method: str = "average", - numeric_only: Optional[bool_t] = None, + numeric_only: Optional[builtins.bool] = None, na_option: str = "keep", - ascending: bool_t = True, - pct: bool_t = False, + ascending: builtins.bool = True, + pct: builtins.bool = False, ) -> FrameOrSeries: """ Compute numerical data ranks (1 through n) along axis. @@ -8295,7 +8297,7 @@ def _align_frame( join="outer", axis=None, level=None, - copy: bool_t = True, + copy: builtins.bool = True, fill_value=None, method=None, limit=None, @@ -8357,7 +8359,7 @@ def _align_series( join="outer", axis=None, level=None, - copy: bool_t = True, + copy: builtins.bool = True, fill_value=None, method=None, limit=None, @@ -8947,7 +8949,11 @@ def tshift( return self._constructor(new_data).__finalize__(self) def truncate( - self: FrameOrSeries, before=None, after=None, axis=None, copy: bool_t = True + self: FrameOrSeries, + before=None, + after=None, + axis=None, + copy: builtins.bool = True, ) -> FrameOrSeries: """ Truncate a Series or DataFrame before and after some index value. @@ -9101,7 +9107,7 @@ def truncate( return result def tz_convert( - self: FrameOrSeries, tz, axis=0, level=None, copy: bool_t = True + self: FrameOrSeries, tz, axis=0, level=None, copy: builtins.bool = True ) -> FrameOrSeries: """ Convert tz-aware axis to target time zone. @@ -9162,7 +9168,7 @@ def tz_localize( tz, axis=0, level=None, - copy: bool_t = True, + copy: builtins.bool = True, ambiguous="raise", nonexistent: str = "raise", ) -> FrameOrSeries: