Skip to content

Commit ff38aad

Browse files
committed
Remove non-standard imports nan and ndarray
Not really thematically related to this PR, but not big enough to merit their own
1 parent b3e2438 commit ff38aad

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

Diff for: pandas/core/frame.py

+12-14
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)
@@ -2781,7 +2780,7 @@ def _reindex_axes(self, axes, level, limit, tolerance, method, fill_value,
27812780

27822781
return frame
27832782

2784-
def _reindex_index(self, new_index, method, copy, level, fill_value=NA,
2783+
def _reindex_index(self, new_index, method, copy, level, fill_value=np.nan,
27852784
limit=None, tolerance=None):
27862785
new_index, indexer = self.index.reindex(new_index, method=method,
27872786
level=level, limit=limit,
@@ -2790,8 +2789,8 @@ def _reindex_index(self, new_index, method, copy, level, fill_value=NA,
27902789
copy=copy, fill_value=fill_value,
27912790
allow_dups=False)
27922791

2793-
def _reindex_columns(self, new_columns, method, copy, level, fill_value=NA,
2794-
limit=None, tolerance=None):
2792+
def _reindex_columns(self, new_columns, method, copy, level,
2793+
fill_value=np.nan, limit=None, tolerance=None):
27952794
new_columns, indexer = self.columns.reindex(new_columns, method=method,
27962795
level=level, limit=limit,
27972796
tolerance=tolerance)
@@ -3770,7 +3769,7 @@ def _combine_series(self, other, func, fill_value=None, axis=None,
37703769
def _combine_series_infer(self, other, func, level=None,
37713770
fill_value=None, try_cast=True):
37723771
if len(other) == 0:
3773-
return self * NA
3772+
return self * np.nan
37743773

37753774
if len(self) == 0:
37763775
# Ambiguous case, use _series so works with DataFrame
@@ -3924,7 +3923,7 @@ def combine(self, other, func, fill_value=None, overwrite=True):
39243923

39253924
if do_fill:
39263925
arr = _ensure_float(arr)
3927-
arr[this_mask & other_mask] = NA
3926+
arr[this_mask & other_mask] = np.nan
39283927

39293928
# try to downcast back to the original dtype
39303929
if needs_i8_conversion_i:
@@ -4543,7 +4542,7 @@ def _apply_empty_result(self, func, axis, reduce, *args, **kwds):
45434542
pass
45444543

45454544
if reduce:
4546-
return Series(NA, index=self._get_agg_axis(axis))
4545+
return Series(np.nan, index=self._get_agg_axis(axis))
45474546
else:
45484547
return self.copy()
45494548

@@ -5161,7 +5160,7 @@ def corr(self, method='pearson', min_periods=1):
51615160

51625161
valid = mask[i] & mask[j]
51635162
if valid.sum() < min_periods:
5164-
c = NA
5163+
c = np.nan
51655164
elif i == j:
51665165
c = 1.
51675166
elif not valid.all():
@@ -5485,7 +5484,7 @@ def idxmin(self, axis=0, skipna=True):
54855484
axis = self._get_axis_number(axis)
54865485
indices = nanops.nanargmin(self.values, axis=axis, skipna=skipna)
54875486
index = self._get_axis(axis)
5488-
result = [index[i] if i >= 0 else NA for i in indices]
5487+
result = [index[i] if i >= 0 else np.nan for i in indices]
54895488
return Series(result, index=self._get_agg_axis(axis))
54905489

54915490
def idxmax(self, axis=0, skipna=True):
@@ -5516,7 +5515,7 @@ def idxmax(self, axis=0, skipna=True):
55165515
axis = self._get_axis_number(axis)
55175516
indices = nanops.nanargmax(self.values, axis=axis, skipna=skipna)
55185517
index = self._get_axis(axis)
5519-
result = [index[i] if i >= 0 else NA for i in indices]
5518+
result = [index[i] if i >= 0 else np.nan for i in indices]
55205519
return Series(result, index=self._get_agg_axis(axis))
55215520

55225521
def _get_agg_axis(self, axis_num):
@@ -5754,9 +5753,8 @@ def isin(self, values):
57545753
2 True True
57555754
"""
57565755
if isinstance(values, dict):
5757-
from collections import defaultdict
57585756
from pandas.core.reshape.concat import concat
5759-
values = defaultdict(list, values)
5757+
values = collections.defaultdict(list, values)
57605758
return concat((self.iloc[:, [i]].isin(values[col])
57615759
for i, col in enumerate(self.columns)), axis=1)
57625760
elif isinstance(values, Series):
@@ -6119,7 +6117,7 @@ def _homogenize(data, index, dtype=None):
61196117
v = _dict_compat(v)
61206118
else:
61216119
v = dict(v)
6122-
v = lib.fast_multiget(v, oindex.values, default=NA)
6120+
v = lib.fast_multiget(v, oindex.values, default=np.nan)
61236121
v = _sanitize_array(v, index, dtype=dtype, copy=False,
61246122
raise_cast_failure=False)
61256123

Diff for: pandas/core/series.py

+4-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,7 @@ 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
2954+
_INDEX_TYPES = np.ndarray, Index, list, tuple
29562955

29572956
# -----------------------------------------------------------------------------
29582957
# Supplementary functions

0 commit comments

Comments
 (0)