17
17
ABCDataFrame ,
18
18
ABCDatetimeIndex ,
19
19
ABCTimedeltaIndex ,
20
- ABCPeriodIndex )
20
+ ABCPeriodIndex ,
21
+ ABCDateOffset )
21
22
from pandas .core .dtypes .common import (
22
23
is_integer ,
23
24
is_bool ,
28
29
is_list_like ,
29
30
_ensure_float64 ,
30
31
is_scalar )
31
- import pandas as pd
32
32
33
33
from pandas .core .base import (PandasObject , SelectionMixin ,
34
34
GroupByMixin )
35
35
import pandas .core .common as com
36
36
import pandas ._libs .window as _window
37
- from pandas . tseries . offsets import DateOffset
37
+
38
38
from pandas import compat
39
39
from pandas .compat .numpy import function as nv
40
40
from pandas .util ._decorators import (Substitution , Appender ,
@@ -254,7 +254,8 @@ def _wrap_result(self, result, block=None, obj=None):
254
254
# coerce if necessary
255
255
if block is not None :
256
256
if is_timedelta64_dtype (block .values .dtype ):
257
- result = pd .to_timedelta (
257
+ from pandas import to_timedelta
258
+ result = to_timedelta (
258
259
result .ravel (), unit = 'ns' ).values .reshape (result .shape )
259
260
260
261
if result .ndim == 1 :
@@ -275,7 +276,7 @@ def _wrap_results(self, results, blocks, obj):
275
276
obj : conformed data (may be resampled)
276
277
"""
277
278
278
- from pandas import Series
279
+ from pandas import Series , concat
279
280
from pandas .core .index import _ensure_index
280
281
281
282
final = []
@@ -290,8 +291,7 @@ def _wrap_results(self, results, blocks, obj):
290
291
# we want to put it back into the results
291
292
# in the same location
292
293
columns = self ._selected_obj .columns
293
- if self .on is not None \
294
- and not self ._on .equals (obj .index ):
294
+ if self .on is not None and not self ._on .equals (obj .index ):
295
295
296
296
name = self ._on .name
297
297
final .append (Series (self ._on , index = obj .index , name = name ))
@@ -309,19 +309,17 @@ def _wrap_results(self, results, blocks, obj):
309
309
310
310
if not len (final ):
311
311
return obj .astype ('float64' )
312
- return pd .concat (final , axis = 1 ).reindex (columns = columns ,
313
- copy = False )
312
+ return concat (final , axis = 1 ).reindex (columns = columns , copy = False )
314
313
315
314
def _center_window (self , result , window ):
316
315
""" center the result in the window """
317
316
if self .axis > result .ndim - 1 :
318
317
raise ValueError ("Requested axis is larger then no. of argument "
319
318
"dimensions" )
320
319
321
- from pandas import Series , DataFrame
322
320
offset = _offset (window , True )
323
321
if offset > 0 :
324
- if isinstance (result , (Series , DataFrame )):
322
+ if isinstance (result , (ABCSeries , ABCDataFrame )):
325
323
result = result .slice_shift (- offset , axis = self .axis )
326
324
else :
327
325
lead_indexer = [slice (None )] * result .ndim
@@ -1085,7 +1083,8 @@ def _on(self):
1085
1083
return self .obj .index
1086
1084
elif (isinstance (self .obj , ABCDataFrame ) and
1087
1085
self .on in self .obj .columns ):
1088
- return pd .Index (self .obj [self .on ])
1086
+ from pandas import Index
1087
+ return Index (self .obj [self .on ])
1089
1088
else :
1090
1089
raise ValueError ("invalid on specified as {0}, "
1091
1090
"must be a column (if DataFrame) "
@@ -1096,7 +1095,7 @@ def validate(self):
1096
1095
1097
1096
# we allow rolling on a datetimelike index
1098
1097
if ((self .obj .empty or self .is_datetimelike ) and
1099
- isinstance (self .window , (compat .string_types , DateOffset ,
1098
+ isinstance (self .window , (compat .string_types , ABCDateOffset ,
1100
1099
timedelta ))):
1101
1100
1102
1101
self ._validate_monotonic ()
@@ -1871,19 +1870,19 @@ def _cov(x, y):
1871
1870
1872
1871
1873
1872
def _flex_binary_moment (arg1 , arg2 , f , pairwise = False ):
1874
- from pandas import Series , DataFrame
1875
1873
1876
- if not (isinstance (arg1 , (np .ndarray , Series , DataFrame )) and
1877
- isinstance (arg2 , (np .ndarray , Series , DataFrame ))):
1874
+ if not (isinstance (arg1 , (np .ndarray , ABCSeries , ABCDataFrame )) and
1875
+ isinstance (arg2 , (np .ndarray , ABCSeries , ABCDataFrame ))):
1878
1876
raise TypeError ("arguments to moment function must be of type "
1879
1877
"np.ndarray/Series/DataFrame" )
1880
1878
1881
- if (isinstance (arg1 , (np .ndarray , Series )) and
1882
- isinstance (arg2 , (np .ndarray , Series ))):
1879
+ if (isinstance (arg1 , (np .ndarray , ABCSeries )) and
1880
+ isinstance (arg2 , (np .ndarray , ABCSeries ))):
1883
1881
X , Y = _prep_binary (arg1 , arg2 )
1884
1882
return f (X , Y )
1885
1883
1886
- elif isinstance (arg1 , DataFrame ):
1884
+ elif isinstance (arg1 , ABCDataFrame ):
1885
+ from pandas import DataFrame
1887
1886
1888
1887
def dataframe_from_int_dict (data , frame_template ):
1889
1888
result = DataFrame (data , index = frame_template .index )
@@ -1892,7 +1891,7 @@ def dataframe_from_int_dict(data, frame_template):
1892
1891
return result
1893
1892
1894
1893
results = {}
1895
- if isinstance (arg2 , DataFrame ):
1894
+ if isinstance (arg2 , ABCDataFrame ):
1896
1895
if pairwise is False :
1897
1896
if arg1 is arg2 :
1898
1897
# special case in order to handle duplicate column names
@@ -1929,7 +1928,7 @@ def dataframe_from_int_dict(data, frame_template):
1929
1928
1930
1929
# TODO: not the most efficient (perf-wise)
1931
1930
# though not bad code-wise
1932
- from pandas import Panel , MultiIndex
1931
+ from pandas import Panel , MultiIndex , concat
1933
1932
1934
1933
with warnings .catch_warnings (record = True ):
1935
1934
p = Panel .from_dict (results ).swapaxes ('items' , 'major' )
@@ -1939,7 +1938,7 @@ def dataframe_from_int_dict(data, frame_template):
1939
1938
p .minor_axis = arg2 .columns [p .minor_axis ]
1940
1939
1941
1940
if len (p .items ):
1942
- result = pd . concat (
1941
+ result = concat (
1943
1942
[p .iloc [i ].T for i in range (len (p .items ))],
1944
1943
keys = p .items )
1945
1944
else :
@@ -2034,8 +2033,7 @@ def _zsqrt(x):
2034
2033
result = np .sqrt (x )
2035
2034
mask = x < 0
2036
2035
2037
- from pandas import DataFrame
2038
- if isinstance (x , DataFrame ):
2036
+ if isinstance (x , ABCDataFrame ):
2039
2037
if mask .values .any ():
2040
2038
result [mask ] = 0
2041
2039
else :
@@ -2060,8 +2058,7 @@ def _prep_binary(arg1, arg2):
2060
2058
2061
2059
2062
2060
def rolling (obj , win_type = None , ** kwds ):
2063
- from pandas import Series , DataFrame
2064
- if not isinstance (obj , (Series , DataFrame )):
2061
+ if not isinstance (obj , (ABCSeries , ABCDataFrame )):
2065
2062
raise TypeError ('invalid type: %s' % type (obj ))
2066
2063
2067
2064
if win_type is not None :
@@ -2074,8 +2071,7 @@ def rolling(obj, win_type=None, **kwds):
2074
2071
2075
2072
2076
2073
def expanding (obj , ** kwds ):
2077
- from pandas import Series , DataFrame
2078
- if not isinstance (obj , (Series , DataFrame )):
2074
+ if not isinstance (obj , (ABCSeries , ABCDataFrame )):
2079
2075
raise TypeError ('invalid type: %s' % type (obj ))
2080
2076
2081
2077
return Expanding (obj , ** kwds )
@@ -2085,8 +2081,7 @@ def expanding(obj, **kwds):
2085
2081
2086
2082
2087
2083
def ewm (obj , ** kwds ):
2088
- from pandas import Series , DataFrame
2089
- if not isinstance (obj , (Series , DataFrame )):
2084
+ if not isinstance (obj , (ABCSeries , ABCDataFrame )):
2090
2085
raise TypeError ('invalid type: %s' % type (obj ))
2091
2086
2092
2087
return EWM (obj , ** kwds )
0 commit comments