From 92ed0e0c214a71af38bd271df45ee244530b8341 Mon Sep 17 00:00:00 2001 From: Andrew Wieteska Date: Sat, 12 Dec 2020 23:30:42 -0500 Subject: [PATCH] typing (bool/str) --- pandas/core/frame.py | 124 ++++++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 49 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index fd7820196f9a9..650809ebcf771 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1440,7 +1440,7 @@ def to_numpy( return result - def to_dict(self, orient="dict", into=dict): + def to_dict(self, orient: str = "dict", into=dict): """ Convert the DataFrame to a dictionary. @@ -1615,15 +1615,15 @@ def to_dict(self, orient="dict", into=dict): def to_gbq( self, - destination_table, - project_id=None, + destination_table: str, + project_id: Optional[str] = None, chunksize=None, - reauth=False, - if_exists="fail", - auth_local_webserver=False, + reauth: bool = False, + if_exists: str = "fail", + auth_local_webserver: bool = False, table_schema=None, - location=None, - progress_bar=True, + location: Optional[str] = None, + progress_bar: bool = True, credentials=None, ) -> None: """ @@ -1728,7 +1728,7 @@ def from_records( index=None, exclude=None, columns=None, - coerce_float=False, + coerce_float: bool = False, nrows=None, ) -> DataFrame: """ @@ -2489,7 +2489,7 @@ def to_html( max_rows=None, max_cols=None, show_dimensions=False, - decimal=".", + decimal: str = ".", bold_rows=True, classes=None, escape=True, @@ -3311,7 +3311,7 @@ def _box_col_values(self, values, loc: int) -> Series: # ---------------------------------------------------------------------- # Unsorted - def query(self, expr, inplace=False, **kwargs): + def query(self, expr: str, inplace: bool = False, **kwargs): """ Query the columns of a DataFrame with a boolean expression. @@ -3475,7 +3475,7 @@ def query(self, expr, inplace=False, **kwargs): else: return result - def eval(self, expr, inplace=False, **kwargs): + def eval(self, expr: str, inplace: bool = False, **kwargs): """ Evaluate a string describing operations on DataFrame columns. @@ -3732,7 +3732,7 @@ def extract_unique_dtypes_from_dtypes_set( return self.iloc[:, keep_these.values] - def insert(self, loc, column, value, allow_duplicates=False) -> None: + def insert(self, loc, column, value, allow_duplicates: bool = False) -> None: """ Insert column into DataFrame at specified location. @@ -3846,7 +3846,7 @@ def assign(self, **kwargs) -> DataFrame: data[k] = com.apply_if_callable(v, data) return data - def _sanitize_column(self, key, value, broadcast=True): + def _sanitize_column(self, key, value, broadcast: bool = True): """ Ensures new columns (which go into the BlockManager as new blocks) are always copied and converted into an array. @@ -4046,7 +4046,7 @@ def _reindex_index( self, new_index, method, - copy, + copy: bool, level, fill_value=np.nan, limit=None, @@ -4066,7 +4066,7 @@ def _reindex_columns( self, new_columns, method, - copy, + copy: bool, level, fill_value=None, limit=None, @@ -4082,7 +4082,7 @@ def _reindex_columns( allow_dups=False, ) - def _reindex_multi(self, axes, copy, fill_value) -> DataFrame: + def _reindex_multi(self, axes, copy: bool, fill_value) -> DataFrame: """ We are guaranteed non-Nones in the axes. """ @@ -4106,12 +4106,12 @@ def _reindex_multi(self, axes, copy, fill_value) -> DataFrame: def align( self, other, - join="outer", + join: str = "outer", axis=None, level=None, - copy=True, + copy: bool = True, fill_value=None, - method=None, + method: Optional[str] = None, limit=None, fill_axis=0, broadcast_axis=None, @@ -4199,8 +4199,8 @@ def drop( index=None, columns=None, level=None, - inplace=False, - errors="raise", + inplace: bool = False, + errors: str = "raise", ): """ Drop specified labels from rows or columns. @@ -4470,9 +4470,9 @@ def rename( def fillna( self, value=None, - method=None, + method: Optional[str] = None, axis=None, - inplace=False, + inplace: bool = False, limit=None, downcast=None, ) -> Optional[DataFrame]: @@ -4533,10 +4533,10 @@ def replace( self, to_replace=None, value=None, - inplace=False, + inplace: bool = False, limit=None, - regex=False, - method="pad", + regex: bool = False, + method: str = "pad", ): return super().replace( to_replace=to_replace, @@ -4616,7 +4616,12 @@ def shift( ) def set_index( - self, keys, drop=True, append=False, inplace=False, verify_integrity=False + self, + keys, + drop: bool = True, + append: bool = False, + inplace: bool = False, + verify_integrity: bool = False, ): """ Set the DataFrame index using existing columns. @@ -5055,7 +5060,9 @@ def notna(self) -> DataFrame: def notnull(self) -> DataFrame: return ~self.isna() - def dropna(self, axis=0, how="any", thresh=None, subset=None, inplace=False): + def dropna( + self, axis=0, how: str = "any", thresh=None, subset=None, inplace: bool = False + ): """ Remove missing values. @@ -5436,10 +5443,10 @@ def sort_values( # type: ignore[override] by, axis=0, ascending=True, - inplace=False, - kind="quicksort", - na_position="last", - ignore_index=False, + inplace: bool = False, + kind: str = "quicksort", + na_position: str = "last", + ignore_index: bool = False, key: ValueKeyFunc = None, ): inplace = validate_bool_kwarg(inplace, "inplace") @@ -5701,7 +5708,7 @@ def value_counts( return counts - def nlargest(self, n, columns, keep="first") -> DataFrame: + def nlargest(self, n, columns, keep: str = "first") -> DataFrame: """ Return the first `n` rows ordered by `columns` in descending order. @@ -5810,7 +5817,7 @@ def nlargest(self, n, columns, keep="first") -> DataFrame: """ return algorithms.SelectNFrame(self, n=n, keep=keep, columns=columns).nlargest() - def nsmallest(self, n, columns, keep="first") -> DataFrame: + def nsmallest(self, n, columns, keep: str = "first") -> DataFrame: """ Return the first `n` rows ordered by `columns` in ascending order. @@ -6234,7 +6241,7 @@ def compare( ) def combine( - self, other: DataFrame, func, fill_value=None, overwrite=True + self, other: DataFrame, func, fill_value=None, overwrite: bool = True ) -> DataFrame: """ Perform column-wise combine with another DataFrame. @@ -6462,7 +6469,12 @@ def combiner(x, y): return self.combine(other, combiner, overwrite=False) def update( - self, other, join="left", overwrite=True, filter_func=None, errors="ignore" + self, + other, + join: str = "left", + overwrite: bool = True, + filter_func=None, + errors: str = "ignore", ) -> None: """ Modify in place using non-NA values from another DataFrame. @@ -7055,7 +7067,7 @@ def pivot_table( observed=observed, ) - def stack(self, level=-1, dropna=True): + def stack(self, level=-1, dropna: bool = True): """ Stack the prescribed level(s) from columns to index. @@ -7636,7 +7648,7 @@ def transform( assert isinstance(result, DataFrame) return result - def apply(self, func, axis=0, raw=False, result_type=None, args=(), **kwds): + def apply(self, func, axis=0, raw: bool = False, result_type=None, args=(), **kwds): """ Apply a function along an axis of the DataFrame. @@ -7861,7 +7873,11 @@ def infer(x): # Merging / joining methods def append( - self, other, ignore_index=False, verify_integrity=False, sort=False + self, + other, + ignore_index: bool = False, + verify_integrity: bool = False, + sort: bool = False, ) -> DataFrame: """ Append rows of `other` to the end of caller, returning a new object. @@ -8002,7 +8018,13 @@ def append( ).__finalize__(self, method="append") def join( - self, other, on=None, how="left", lsuffix="", rsuffix="", sort=False + self, + other, + on=None, + how: str = "left", + lsuffix: str = "", + rsuffix: str = "", + sort: bool = False, ) -> DataFrame: """ Join columns of another DataFrame. @@ -8639,7 +8661,7 @@ def c(x): # ---------------------------------------------------------------------- # ndarray-like stats methods - def count(self, axis=0, level=None, numeric_only=False): + def count(self, axis=0, level=None, numeric_only: bool = False): """ Count non-NA cells for each column or row. @@ -8794,8 +8816,8 @@ def _reduce( name: str, *, axis=0, - skipna=True, - numeric_only=None, + skipna: bool = True, + numeric_only: Optional[bool] = None, filter_type=None, **kwds, ): @@ -8901,7 +8923,7 @@ def _get_data() -> DataFrame: result = self._constructor_sliced(result, index=labels) return result - def nunique(self, axis=0, dropna=True) -> Series: + def nunique(self, axis=0, dropna: bool = True) -> Series: """ Count distinct observations over requested axis. @@ -8941,7 +8963,7 @@ def nunique(self, axis=0, dropna=True) -> Series: """ return self.apply(Series.nunique, axis=axis, dropna=dropna) - def idxmin(self, axis=0, skipna=True) -> Series: + def idxmin(self, axis=0, skipna: bool = True) -> Series: """ Return index of first occurrence of minimum over requested axis. @@ -9018,7 +9040,7 @@ def idxmin(self, axis=0, skipna=True) -> Series: result = [index[i] if i >= 0 else np.nan for i in indices] return self._constructor_sliced(result, index=self._get_agg_axis(axis)) - def idxmax(self, axis=0, skipna=True) -> Series: + def idxmax(self, axis=0, skipna: bool = True) -> Series: """ Return index of first occurrence of maximum over requested axis. @@ -9106,7 +9128,9 @@ def _get_agg_axis(self, axis_num: int) -> Index: else: raise ValueError(f"Axis must be 0 or 1 (got {repr(axis_num)})") - def mode(self, axis=0, numeric_only=False, dropna=True) -> DataFrame: + def mode( + self, axis=0, numeric_only: bool = False, dropna: bool = True + ) -> DataFrame: """ Get the mode(s) of each element along the selected axis. @@ -9193,7 +9217,9 @@ def f(s): return data.apply(f, axis=axis) - def quantile(self, q=0.5, axis=0, numeric_only=True, interpolation="linear"): + def quantile( + self, q=0.5, axis=0, numeric_only: bool = True, interpolation: str = "linear" + ): """ Return values at the given quantile over requested axis.