diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 9d63bd2e120aae..027a4275552531 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -20,7 +20,6 @@ import warnings from textwrap import dedent -from numpy import nan as NA import numpy as np import numpy.ma as ma @@ -436,7 +435,7 @@ def _init_dict(self, data, index, columns, dtype=None): else: v = np.empty(len(index), dtype=dtype) - v.fill(NA) + v.fill(np.nan) else: v = data[k] data_names.append(k) @@ -1437,8 +1436,8 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None, columns : sequence, optional Columns to write header : boolean or list of string, default True - Write out column names. If a list of string is given it is assumed - to be aliases for the column names + Write out the column names. If a list of strings is given it is + assumed to be aliases for the column names index : boolean, default True Write row names (index) index_label : string or sequence, or False, default None @@ -1622,8 +1621,9 @@ def to_parquet(self, fname, engine='auto', compression='snappy', to_parquet(self, fname, engine, compression=compression, **kwargs) - @Substitution(header='Write out column names. If a list of string is given, \ -it is assumed to be aliases for the column names') + @Substitution(header='Write out the column names. If a list of strings ' + 'is given, it is assumed to be aliases for the ' + 'column names') @Appender(fmt.docstring_to_string, indents=1) def to_string(self, buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, @@ -2805,7 +2805,7 @@ def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, return frame - def _reindex_index(self, new_index, method, copy, level, fill_value=NA, + def _reindex_index(self, new_index, method, copy, level, fill_value=np.nan, limit=None, tolerance=None): new_index, indexer = self.index.reindex(new_index, method=method, level=level, limit=limit, @@ -2814,8 +2814,8 @@ def _reindex_index(self, new_index, method, copy, level, fill_value=NA, copy=copy, fill_value=fill_value, allow_dups=False) - def _reindex_columns(self, new_columns, method, copy, level, fill_value=NA, - limit=None, tolerance=None): + def _reindex_columns(self, new_columns, method, copy, level, + fill_value=np.nan, limit=None, tolerance=None): new_columns, indexer = self.columns.reindex(new_columns, method=method, level=level, limit=limit, tolerance=tolerance) @@ -3794,7 +3794,7 @@ def _combine_series(self, other, func, fill_value=None, axis=None, def _combine_series_infer(self, other, func, level=None, fill_value=None, try_cast=True): if len(other) == 0: - return self * NA + return self * np.nan if len(self) == 0: # Ambiguous case, use _series so works with DataFrame @@ -3948,7 +3948,7 @@ def combine(self, other, func, fill_value=None, overwrite=True): if do_fill: arr = _ensure_float(arr) - arr[this_mask & other_mask] = NA + arr[this_mask & other_mask] = np.nan # try to downcast back to the original dtype if needs_i8_conversion_i: @@ -4567,7 +4567,7 @@ def _apply_empty_result(self, func, axis, reduce, *args, **kwds): pass if reduce: - return Series(NA, index=self._get_agg_axis(axis)) + return Series(np.nan, index=self._get_agg_axis(axis)) else: return self.copy() @@ -5185,7 +5185,7 @@ def corr(self, method='pearson', min_periods=1): valid = mask[i] & mask[j] if valid.sum() < min_periods: - c = NA + c = np.nan elif i == j: c = 1. elif not valid.all(): @@ -5509,7 +5509,7 @@ def idxmin(self, axis=0, skipna=True): axis = self._get_axis_number(axis) indices = nanops.nanargmin(self.values, axis=axis, skipna=skipna) index = self._get_axis(axis) - result = [index[i] if i >= 0 else NA for i in indices] + result = [index[i] if i >= 0 else np.nan for i in indices] return Series(result, index=self._get_agg_axis(axis)) def idxmax(self, axis=0, skipna=True): @@ -5540,7 +5540,7 @@ def idxmax(self, axis=0, skipna=True): axis = self._get_axis_number(axis) indices = nanops.nanargmax(self.values, axis=axis, skipna=skipna) index = self._get_axis(axis) - result = [index[i] if i >= 0 else NA for i in indices] + result = [index[i] if i >= 0 else np.nan for i in indices] return Series(result, index=self._get_agg_axis(axis)) def _get_agg_axis(self, axis_num): @@ -5778,9 +5778,8 @@ def isin(self, values): 2 True True """ if isinstance(values, dict): - from collections import defaultdict from pandas.core.reshape.concat import concat - values = defaultdict(list, values) + values = collections.defaultdict(list, values) return concat((self.iloc[:, [i]].isin(values[col]) for i, col in enumerate(self.columns)), axis=1) elif isinstance(values, Series): @@ -6143,7 +6142,7 @@ def _homogenize(data, index, dtype=None): v = _dict_compat(v) else: v = dict(v) - v = lib.fast_multiget(v, oindex.values, default=NA) + v = lib.fast_multiget(v, oindex.values, default=np.nan) v = _sanitize_array(v, index, dtype=dtype, copy=False, raise_cast_failure=False) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ec44dce0da9bc4..442ec93d940235 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1207,7 +1207,7 @@ def _repr_latex_(self): columns : sequence, optional Columns to write header : boolean or list of string, default True - Write out column names. If a list of string is given it is + Write out the column names. If a list of strings is given it is assumed to be aliases for the column names index : boolean, default True Write row names (index) @@ -1702,8 +1702,9 @@ def to_xarray(self): .. versionadded:: 0.20.0 """ - @Substitution(header='Write out column names. If a list of string is given, \ -it is assumed to be aliases for the column names.') + @Substitution(header='Write out the column names. If a list of strings ' + 'is given, it is assumed to be aliases for the ' + 'column names.') @Appender(_shared_docs['to_latex'] % _shared_doc_kwargs) def to_latex(self, buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 8f6b00fd204cc4..109183827de4e8 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1,5 +1,5 @@ # pylint: disable=W0223 - +import textwrap import warnings import numpy as np from pandas.compat import range, zip @@ -1288,13 +1288,13 @@ class _IXIndexer(_NDFrameIndexer): def __init__(self, obj, name): - _ix_deprecation_warning = """ -.ix is deprecated. Please use -.loc for label based indexing or -.iloc for positional indexing + _ix_deprecation_warning = textwrap.dedent(""" + .ix is deprecated. Please use + .loc for label based indexing or + .iloc for positional indexing -See the documentation here: -http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated""" # noqa + See the documentation here: + http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated""") # noqa warnings.warn(_ix_deprecation_warning, DeprecationWarning, stacklevel=3) diff --git a/pandas/core/series.py b/pandas/core/series.py index c1a3c96b02c309..78b64e870c1549 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -10,7 +10,6 @@ import warnings from textwrap import dedent -from numpy import nan, ndarray import numpy as np import numpy.ma as ma @@ -212,13 +211,13 @@ def __init__(self, data=None, index=None, dtype=None, name=None, data = np.nan # GH #12169 elif isinstance(index, (PeriodIndex, TimedeltaIndex)): - data = ([data.get(i, nan) for i in index] + data = ([data.get(i, np.nan) for i in index] if data else np.nan) else: data = lib.fast_multiget(data, index.values, default=np.nan) except TypeError: - data = ([data.get(i, nan) for i in index] + data = ([data.get(i, np.nan) for i in index] if data else np.nan) elif isinstance(data, SingleBlockManager): @@ -1688,7 +1687,7 @@ def _binop(self, other, func, level=None, fill_value=None): result.name = None return result - def combine(self, other, func, fill_value=nan): + def combine(self, other, func, fill_value=np.nan): """ Perform elementwise binary operation on two Series using given function with optional fill value when an index is missing from one Series or @@ -2954,7 +2953,6 @@ def _dir_additions(self): Series._add_numeric_operations() Series._add_series_only_operations() Series._add_series_or_dataframe_operations() -_INDEX_TYPES = ndarray, Index, list, tuple # ----------------------------------------------------------------------------- # Supplementary functions