Skip to content

Commit a4c0e72

Browse files
jbrockmendeljreback
authored andcommitted
MAINT: Remove non-standard and inconsistently-used imports (#17085)
1 parent 3fadc62 commit a4c0e72

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

pandas/core/frame.py

+17-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import warnings
2121
from textwrap import dedent
2222

23-
from numpy import nan as NA
2423
import numpy as np
2524
import numpy.ma as ma
2625

@@ -436,7 +435,7 @@ def _init_dict(self, data, index, columns, dtype=None):
436435
else:
437436
v = np.empty(len(index), dtype=dtype)
438437

439-
v.fill(NA)
438+
v.fill(np.nan)
440439
else:
441440
v = data[k]
442441
data_names.append(k)
@@ -1437,8 +1436,8 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
14371436
columns : sequence, optional
14381437
Columns to write
14391438
header : boolean or list of string, default True
1440-
Write out column names. If a list of string is given it is assumed
1441-
to be aliases for the column names
1439+
Write out the column names. If a list of strings is given it is
1440+
assumed to be aliases for the column names
14421441
index : boolean, default True
14431442
Write row names (index)
14441443
index_label : string or sequence, or False, default None
@@ -1622,8 +1621,9 @@ def to_parquet(self, fname, engine='auto', compression='snappy',
16221621
to_parquet(self, fname, engine,
16231622
compression=compression, **kwargs)
16241623

1625-
@Substitution(header='Write out column names. If a list of string is given, \
1626-
it is assumed to be aliases for the column names')
1624+
@Substitution(header='Write out the column names. If a list of strings '
1625+
'is given, it is assumed to be aliases for the '
1626+
'column names')
16271627
@Appender(fmt.docstring_to_string, indents=1)
16281628
def to_string(self, buf=None, columns=None, col_space=None, header=True,
16291629
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,
28052805

28062806
return frame
28072807

2808-
def _reindex_index(self, new_index, method, copy, level, fill_value=NA,
2808+
def _reindex_index(self, new_index, method, copy, level, fill_value=np.nan,
28092809
limit=None, tolerance=None):
28102810
new_index, indexer = self.index.reindex(new_index, method=method,
28112811
level=level, limit=limit,
@@ -2814,8 +2814,8 @@ def _reindex_index(self, new_index, method, copy, level, fill_value=NA,
28142814
copy=copy, fill_value=fill_value,
28152815
allow_dups=False)
28162816

2817-
def _reindex_columns(self, new_columns, method, copy, level, fill_value=NA,
2818-
limit=None, tolerance=None):
2817+
def _reindex_columns(self, new_columns, method, copy, level,
2818+
fill_value=np.nan, limit=None, tolerance=None):
28192819
new_columns, indexer = self.columns.reindex(new_columns, method=method,
28202820
level=level, limit=limit,
28212821
tolerance=tolerance)
@@ -3794,7 +3794,7 @@ def _combine_series(self, other, func, fill_value=None, axis=None,
37943794
def _combine_series_infer(self, other, func, level=None,
37953795
fill_value=None, try_cast=True):
37963796
if len(other) == 0:
3797-
return self * NA
3797+
return self * np.nan
37983798

37993799
if len(self) == 0:
38003800
# Ambiguous case, use _series so works with DataFrame
@@ -3948,7 +3948,7 @@ def combine(self, other, func, fill_value=None, overwrite=True):
39483948

39493949
if do_fill:
39503950
arr = _ensure_float(arr)
3951-
arr[this_mask & other_mask] = NA
3951+
arr[this_mask & other_mask] = np.nan
39523952

39533953
# try to downcast back to the original dtype
39543954
if needs_i8_conversion_i:
@@ -4567,7 +4567,7 @@ def _apply_empty_result(self, func, axis, reduce, *args, **kwds):
45674567
pass
45684568

45694569
if reduce:
4570-
return Series(NA, index=self._get_agg_axis(axis))
4570+
return Series(np.nan, index=self._get_agg_axis(axis))
45714571
else:
45724572
return self.copy()
45734573

@@ -5185,7 +5185,7 @@ def corr(self, method='pearson', min_periods=1):
51855185

51865186
valid = mask[i] & mask[j]
51875187
if valid.sum() < min_periods:
5188-
c = NA
5188+
c = np.nan
51895189
elif i == j:
51905190
c = 1.
51915191
elif not valid.all():
@@ -5509,7 +5509,7 @@ def idxmin(self, axis=0, skipna=True):
55095509
axis = self._get_axis_number(axis)
55105510
indices = nanops.nanargmin(self.values, axis=axis, skipna=skipna)
55115511
index = self._get_axis(axis)
5512-
result = [index[i] if i >= 0 else NA for i in indices]
5512+
result = [index[i] if i >= 0 else np.nan for i in indices]
55135513
return Series(result, index=self._get_agg_axis(axis))
55145514

55155515
def idxmax(self, axis=0, skipna=True):
@@ -5540,7 +5540,7 @@ def idxmax(self, axis=0, skipna=True):
55405540
axis = self._get_axis_number(axis)
55415541
indices = nanops.nanargmax(self.values, axis=axis, skipna=skipna)
55425542
index = self._get_axis(axis)
5543-
result = [index[i] if i >= 0 else NA for i in indices]
5543+
result = [index[i] if i >= 0 else np.nan for i in indices]
55445544
return Series(result, index=self._get_agg_axis(axis))
55455545

55465546
def _get_agg_axis(self, axis_num):
@@ -5778,9 +5778,8 @@ def isin(self, values):
57785778
2 True True
57795779
"""
57805780
if isinstance(values, dict):
5781-
from collections import defaultdict
57825781
from pandas.core.reshape.concat import concat
5783-
values = defaultdict(list, values)
5782+
values = collections.defaultdict(list, values)
57845783
return concat((self.iloc[:, [i]].isin(values[col])
57855784
for i, col in enumerate(self.columns)), axis=1)
57865785
elif isinstance(values, Series):
@@ -6143,7 +6142,7 @@ def _homogenize(data, index, dtype=None):
61436142
v = _dict_compat(v)
61446143
else:
61456144
v = dict(v)
6146-
v = lib.fast_multiget(v, oindex.values, default=NA)
6145+
v = lib.fast_multiget(v, oindex.values, default=np.nan)
61476146
v = _sanitize_array(v, index, dtype=dtype, copy=False,
61486147
raise_cast_failure=False)
61496148

pandas/core/generic.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ def _repr_latex_(self):
12071207
columns : sequence, optional
12081208
Columns to write
12091209
header : boolean or list of string, default True
1210-
Write out column names. If a list of string is given it is
1210+
Write out the column names. If a list of strings is given it is
12111211
assumed to be aliases for the column names
12121212
index : boolean, default True
12131213
Write row names (index)
@@ -1702,8 +1702,9 @@ def to_xarray(self):
17021702
.. versionadded:: 0.20.0
17031703
"""
17041704

1705-
@Substitution(header='Write out column names. If a list of string is given, \
1706-
it is assumed to be aliases for the column names.')
1705+
@Substitution(header='Write out the column names. If a list of strings '
1706+
'is given, it is assumed to be aliases for the '
1707+
'column names.')
17071708
@Appender(_shared_docs['to_latex'] % _shared_doc_kwargs)
17081709
def to_latex(self, buf=None, columns=None, col_space=None, header=True,
17091710
index=True, na_rep='NaN', formatters=None, float_format=None,

pandas/core/indexing.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pylint: disable=W0223
2-
2+
import textwrap
33
import warnings
44
import numpy as np
55
from pandas.compat import range, zip
@@ -1288,13 +1288,13 @@ class _IXIndexer(_NDFrameIndexer):
12881288

12891289
def __init__(self, obj, name):
12901290

1291-
_ix_deprecation_warning = """
1292-
.ix is deprecated. Please use
1293-
.loc for label based indexing or
1294-
.iloc for positional indexing
1291+
_ix_deprecation_warning = textwrap.dedent("""
1292+
.ix is deprecated. Please use
1293+
.loc for label based indexing or
1294+
.iloc for positional indexing
12951295
1296-
See the documentation here:
1297-
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated""" # noqa
1296+
See the documentation here:
1297+
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated""") # noqa
12981298

12991299
warnings.warn(_ix_deprecation_warning,
13001300
DeprecationWarning, stacklevel=3)

pandas/core/series.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import warnings
1111
from textwrap import dedent
1212

13-
from numpy import nan, ndarray
1413
import numpy as np
1514
import numpy.ma as ma
1615

@@ -210,13 +209,13 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
210209
data = np.nan
211210
# GH #12169
212211
elif isinstance(index, (PeriodIndex, TimedeltaIndex)):
213-
data = ([data.get(i, nan) for i in index]
212+
data = ([data.get(i, np.nan) for i in index]
214213
if data else np.nan)
215214
else:
216215
data = lib.fast_multiget(data, index.values,
217216
default=np.nan)
218217
except TypeError:
219-
data = ([data.get(i, nan) for i in index]
218+
data = ([data.get(i, np.nan) for i in index]
220219
if data else np.nan)
221220

222221
elif isinstance(data, SingleBlockManager):
@@ -1686,7 +1685,7 @@ def _binop(self, other, func, level=None, fill_value=None):
16861685
result.name = None
16871686
return result
16881687

1689-
def combine(self, other, func, fill_value=nan):
1688+
def combine(self, other, func, fill_value=np.nan):
16901689
"""
16911690
Perform elementwise binary operation on two Series using given function
16921691
with optional fill value when an index is missing from one Series or
@@ -2952,7 +2951,6 @@ def _dir_additions(self):
29522951
Series._add_numeric_operations()
29532952
Series._add_series_only_operations()
29542953
Series._add_series_or_dataframe_operations()
2955-
_INDEX_TYPES = ndarray, Index, list, tuple
29562954

29572955
# -----------------------------------------------------------------------------
29582956
# Supplementary functions

0 commit comments

Comments
 (0)