Skip to content

MAINT: Remove non-standard and inconsistently-used imports #17085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 3, 2017
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
35 changes: 17 additions & 18 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Copy link
Member

Choose a reason for hiding this comment

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

Just wanted to re-add this since my response got hidden: if there are other places that use this documentation, feel free to patch those too. For bonus points, go ahead and see if you can create a shared resource in a _shared_docs dictionary for example that we can import and plugin this docstring.

Copy link
Member Author

Choose a reason for hiding this comment

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

Already copied the edits into the other docstrings, choosing bed over _shared_docs.

Copy link
Member

Choose a reason for hiding this comment

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

choosing bed over _shared_docs.

That's fair. Let me know if you're able to get around to the _shared_docs (@jreback thoughts?) once you get up 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

I suggest moving on and leaving this be. As it is to_csv.__doc__ is all in one piece and I'm not inclined to disturb it.

Unrelated: is there a time in the foreseeable future when Panel etc will be deprecated-as-in-deleted?

Copy link
Member

Choose a reason for hiding this comment

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

As it is to_csv.doc is all in one piece and I'm not inclined to disturb it.

Fair enough. I can discuss with @jreback how we might want to proceed with this.

Regarding Panel, I do not know at this point. My guess is 1.0, but I would wait to see what @jreback or @jorisvandenbossche have to say about this.

@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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# pylint: disable=W0223

import textwrap
import warnings
import numpy as np
from pandas.compat import range, zip
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import warnings
from textwrap import dedent

from numpy import nan, ndarray
import numpy as np
import numpy.ma as ma

Expand Down Expand Up @@ -210,13 +209,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):
Expand Down Expand Up @@ -1686,7 +1685,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
Expand Down Expand Up @@ -2952,7 +2951,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
Expand Down