Skip to content

Commit 2630345

Browse files
committed
CLN: remove pandas.util.misc
CLN: move _fill_zeros -> missing.py CLN: rename missing.* methods w/o leading _
1 parent 0f754b0 commit 2630345

File tree

13 files changed

+125
-153
lines changed

13 files changed

+125
-153
lines changed

pandas/compat/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,15 @@ def import_lzma():
242242
import lzma
243243
return lzma
244244

245+
def set_function_name(f, name, cls):
246+
""" Bind the name/qualname attributes of the function """
247+
f.__name__ = name
248+
f.__qualname__ = '{klass}.{name}'.format(
249+
klass=cls.__name__,
250+
name=name)
251+
f.__module__ = cls.__module__
252+
return f
253+
245254
else:
246255
string_types = basestring,
247256
integer_types = (int, long)
@@ -284,6 +293,11 @@ def import_lzma():
284293
from backports import lzma
285294
return lzma
286295

296+
def set_function_name(f, name, cls):
297+
""" Bind the name attributes of the function """
298+
f.__name__ = name
299+
return f
300+
287301
string_and_binary_types = string_types + (binary_type,)
288302

289303

@@ -369,6 +383,10 @@ def __reduce__(self): # optional, for pickle support
369383

370384

371385
# https://github.com/pydata/pandas/pull/9123
386+
def is_platform_little_endian():
387+
""" am I little endian """
388+
return sys.byteorder == 'little'
389+
372390
def is_platform_windows():
373391
return sys.platform == 'win32' or sys.platform == 'cygwin'
374392

pandas/core/common.py

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import re
66
import collections
77
import numbers
8-
import types
98
from datetime import datetime, timedelta
109
from functools import partial
1110

@@ -130,31 +129,6 @@ def __instancecheck__(cls, inst):
130129
ABCGeneric = _ABCGeneric("ABCGeneric", tuple(), {})
131130

132131

133-
def bind_method(cls, name, func):
134-
"""Bind a method to class, python 2 and python 3 compatible.
135-
136-
Parameters
137-
----------
138-
139-
cls : type
140-
class to receive bound method
141-
name : basestring
142-
name of method on class instance
143-
func : function
144-
function to be bound as method
145-
146-
147-
Returns
148-
-------
149-
None
150-
"""
151-
# only python 2 has bound/unbound method issue
152-
if not compat.PY3:
153-
setattr(cls, name, types.MethodType(func, None, cls))
154-
else:
155-
setattr(cls, name, func)
156-
157-
158132
def isnull(obj):
159133
"""Detect missing values (NaN in numeric arrays, None/NaN in object arrays)
160134
@@ -1466,60 +1440,6 @@ def _lcd_dtypes(a_dtype, b_dtype):
14661440
return np.object
14671441

14681442

1469-
def _fill_zeros(result, x, y, name, fill):
1470-
"""
1471-
if this is a reversed op, then flip x,y
1472-
1473-
if we have an integer value (or array in y)
1474-
and we have 0's, fill them with the fill,
1475-
return the result
1476-
1477-
mask the nan's from x
1478-
"""
1479-
if fill is None or is_float_dtype(result):
1480-
return result
1481-
1482-
if name.startswith(('r', '__r')):
1483-
x, y = y, x
1484-
1485-
is_typed_variable = (hasattr(y, 'dtype') or hasattr(y, 'type'))
1486-
is_scalar = lib.isscalar(y)
1487-
1488-
if not is_typed_variable and not is_scalar:
1489-
return result
1490-
1491-
if is_scalar:
1492-
y = np.array(y)
1493-
1494-
if is_integer_dtype(y):
1495-
1496-
if (y == 0).any():
1497-
1498-
# GH 7325, mask and nans must be broadcastable (also: PR 9308)
1499-
# Raveling and then reshaping makes np.putmask faster
1500-
mask = ((y == 0) & ~np.isnan(result)).ravel()
1501-
1502-
shape = result.shape
1503-
result = result.astype('float64', copy=False).ravel()
1504-
1505-
np.putmask(result, mask, fill)
1506-
1507-
# if we have a fill of inf, then sign it correctly
1508-
# (GH 6178 and PR 9308)
1509-
if np.isinf(fill):
1510-
signs = np.sign(y if name.startswith(('r', '__r')) else x)
1511-
negative_inf_mask = (signs.ravel() < 0) & mask
1512-
np.putmask(result, negative_inf_mask, -fill)
1513-
1514-
if "floordiv" in name: # (PR 9308)
1515-
nan_mask = ((y == 0) & (x == 0)).ravel()
1516-
np.putmask(result, nan_mask, np.nan)
1517-
1518-
result = result.reshape(shape)
1519-
1520-
return result
1521-
1522-
15231443
def _consensus_name_attr(objs):
15241444
name = objs[0].name
15251445
for obj in objs[1:]:

pandas/core/generic.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
from pandas.core.internals import BlockManager
1818
import pandas.core.algorithms as algos
1919
import pandas.core.common as com
20-
import pandas.core.missing as mis
20+
import pandas.core.missing as missing
2121
import pandas.core.datetools as datetools
2222
from pandas import compat
23-
from pandas.compat import map, zip, lrange, string_types, isidentifier, PY3
23+
from pandas.compat import (map, zip, lrange, string_types,
24+
isidentifier, set_function_name)
2425
from pandas.core.common import (isnull, notnull, is_list_like,
2526
_values_from_object, _maybe_promote,
2627
_maybe_box_datetimelike, ABCSeries,
@@ -51,7 +52,7 @@ def _single_replace(self, to_replace, method, inplace, limit):
5152

5253
orig_dtype = self.dtype
5354
result = self if inplace else self.copy()
54-
fill_f = mis._get_fill_func(method)
55+
fill_f = missing.get_fill_func(method)
5556

5657
mask = com.mask_missing(result.values, to_replace)
5758
values = fill_f(result.values, limit=limit, mask=mask)
@@ -2189,7 +2190,7 @@ def reindex(self, *args, **kwargs):
21892190

21902191
# construct the args
21912192
axes, kwargs = self._construct_axes_from_arguments(args, kwargs)
2192-
method = mis._clean_reindex_fill_method(kwargs.pop('method', None))
2193+
method = missing.clean_reindex_fill_method(kwargs.pop('method', None))
21932194
level = kwargs.pop('level', None)
21942195
copy = kwargs.pop('copy', True)
21952196
limit = kwargs.pop('limit', None)
@@ -2304,7 +2305,7 @@ def reindex_axis(self, labels, axis=0, method=None, level=None, copy=True,
23042305

23052306
axis_name = self._get_axis_name(axis)
23062307
axis_values = self._get_axis(axis_name)
2307-
method = mis._clean_reindex_fill_method(method)
2308+
method = missing.clean_reindex_fill_method(method)
23082309
new_index, indexer = axis_values.reindex(labels, method, level,
23092310
limit=limit)
23102311
return self._reindex_with_indexers({axis: [new_index, indexer]},
@@ -3099,7 +3100,7 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
30993100
if axis is None:
31003101
axis = 0
31013102
axis = self._get_axis_number(axis)
3102-
method = mis._clean_fill_method(method)
3103+
method = missing.clean_fill_method(method)
31033104

31043105
from pandas import DataFrame
31053106
if value is None:
@@ -3132,7 +3133,7 @@ def fillna(self, value=None, method=None, axis=None, inplace=False,
31323133

31333134
else:
31343135
# 2d or less
3135-
method = mis._clean_fill_method(method)
3136+
method = missing.clean_fill_method(method)
31363137
new_data = self._data.interpolate(method=method, axis=axis,
31373138
limit=limit, inplace=inplace,
31383139
coerce=True,
@@ -4121,7 +4122,7 @@ def align(self, other, join='outer', axis=None, level=None, copy=True,
41214122
fill_value=None, method=None, limit=None, fill_axis=0,
41224123
broadcast_axis=None):
41234124
from pandas import DataFrame, Series
4124-
method = mis._clean_fill_method(method)
4125+
method = missing.clean_fill_method(method)
41254126

41264127
if broadcast_axis == 1 and self.ndim != other.ndim:
41274128
if isinstance(self, Series):
@@ -5238,16 +5239,6 @@ def _doc_parms(cls):
52385239
%(outname)s : %(name1)s\n"""
52395240

52405241

5241-
def _set_function_name(f, name, cls):
5242-
f.__name__ = name
5243-
if PY3:
5244-
f.__qualname__ = '{klass}.{name}'.format(
5245-
klass=cls.__name__,
5246-
name=name)
5247-
f.__module__ = cls.__module__
5248-
return f
5249-
5250-
52515242
def _make_stat_function(cls, name, name1, name2, axis_descr, desc, f):
52525243
@Substitution(outname=name, desc=desc, name1=name1, name2=name2,
52535244
axis_descr=axis_descr)
@@ -5265,7 +5256,7 @@ def stat_func(self, axis=None, skipna=None, level=None, numeric_only=None,
52655256
return self._reduce(f, name, axis=axis, skipna=skipna,
52665257
numeric_only=numeric_only)
52675258

5268-
return _set_function_name(stat_func, name, cls)
5259+
return set_function_name(stat_func, name, cls)
52695260

52705261

52715262
def _make_stat_function_ddof(cls, name, name1, name2, axis_descr, desc, f):
@@ -5285,7 +5276,7 @@ def stat_func(self, axis=None, skipna=None, level=None, ddof=1,
52855276
return self._reduce(f, name, axis=axis, numeric_only=numeric_only,
52865277
skipna=skipna, ddof=ddof)
52875278

5288-
return _set_function_name(stat_func, name, cls)
5279+
return set_function_name(stat_func, name, cls)
52895280

52905281

52915282
def _make_cum_function(cls, name, name1, name2, axis_descr, desc, accum_func,
@@ -5320,7 +5311,7 @@ def cum_func(self, axis=None, dtype=None, out=None, skipna=True, **kwargs):
53205311
d['copy'] = False
53215312
return self._constructor(result, **d).__finalize__(self)
53225313

5323-
return _set_function_name(cum_func, name, cls)
5314+
return set_function_name(cum_func, name, cls)
53245315

53255316

53265317
def _make_logical_function(cls, name, name1, name2, axis_descr, desc, f):
@@ -5344,7 +5335,7 @@ def logical_func(self, axis=None, bool_only=None, skipna=None, level=None,
53445335
numeric_only=bool_only, filter_type='bool',
53455336
name=name)
53465337

5347-
return _set_function_name(logical_func, name, cls)
5338+
return set_function_name(logical_func, name, cls)
53485339

53495340

53505341
# install the indexes

pandas/core/internals.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pandas.core.categorical import Categorical, maybe_to_categorical
2828
from pandas.tseries.index import DatetimeIndex
2929
import pandas.core.common as com
30-
import pandas.core.missing as mis
30+
import pandas.core.missing as missing
3131
import pandas.core.convert as convert
3232
from pandas.sparse.array import _maybe_to_sparse, SparseArray
3333
import pandas.lib as lib
@@ -872,7 +872,7 @@ def check_int_bool(self, inplace):
872872

873873
# a fill na type method
874874
try:
875-
m = mis._clean_fill_method(method)
875+
m = missing.clean_fill_method(method)
876876
except:
877877
m = None
878878

@@ -887,7 +887,7 @@ def check_int_bool(self, inplace):
887887
downcast=downcast, mgr=mgr)
888888
# try an interp method
889889
try:
890-
m = mis._clean_interp_method(method, **kwargs)
890+
m = missing.clean_interp_method(method, **kwargs)
891891
except:
892892
m = None
893893

@@ -920,9 +920,9 @@ def _interpolate_with_fill(self, method='pad', axis=0, inplace=False,
920920
values = self.values if inplace else self.values.copy()
921921
values, _, fill_value, _ = self._try_coerce_args(values, fill_value)
922922
values = self._try_operate(values)
923-
values = mis.interpolate_2d(values, method=method, axis=axis,
924-
limit=limit, fill_value=fill_value,
925-
dtype=self.dtype)
923+
values = missing.interpolate_2d(values, method=method, axis=axis,
924+
limit=limit, fill_value=fill_value,
925+
dtype=self.dtype)
926926
values = self._try_coerce_result(values)
927927

928928
blocks = [self.make_block(values, klass=self.__class__, fastpath=True)]
@@ -955,11 +955,11 @@ def func(x):
955955

956956
# process a 1-d slice, returning it
957957
# should the axis argument be handled below in apply_along_axis?
958-
# i.e. not an arg to mis.interpolate_1d
959-
return mis.interpolate_1d(index, x, method=method, limit=limit,
960-
limit_direction=limit_direction,
961-
fill_value=fill_value,
962-
bounds_error=False, **kwargs)
958+
# i.e. not an arg to missing.interpolate_1d
959+
return missing.interpolate_1d(index, x, method=method, limit=limit,
960+
limit_direction=limit_direction,
961+
fill_value=fill_value,
962+
bounds_error=False, **kwargs)
963963

964964
# interp each column independently
965965
interp_values = np.apply_along_axis(func, axis, data)
@@ -2414,8 +2414,8 @@ def make_block_same_class(self, values, placement, sparse_index=None,
24142414
def interpolate(self, method='pad', axis=0, inplace=False, limit=None,
24152415
fill_value=None, **kwargs):
24162416

2417-
values = mis.interpolate_2d(self.values.to_dense(), method, axis,
2418-
limit, fill_value)
2417+
values = missing.interpolate_2d(self.values.to_dense(), method, axis,
2418+
limit, fill_value)
24192419
return self.make_block_same_class(values=values,
24202420
placement=self.mgr_locs)
24212421

@@ -3851,8 +3851,10 @@ def reindex(self, new_axis, indexer=None, method=None, fill_value=None,
38513851

38523852
# fill if needed
38533853
if method is not None or limit is not None:
3854-
new_values = mis.interpolate_2d(new_values, method=method,
3855-
limit=limit, fill_value=fill_value)
3854+
new_values = missing.interpolate_2d(new_values,
3855+
method=method,
3856+
limit=limit,
3857+
fill_value=fill_value)
38563858

38573859
if self._block.is_sparse:
38583860
make_block = self._block.make_block_same_class

0 commit comments

Comments
 (0)