@@ -169,33 +169,38 @@ def isin(comps, values):
169
169
raise TypeError ("only list-like objects are allowed to be passed"
170
170
" to isin(), you passed a "
171
171
"[{0}]" .format (type (comps ).__name__ ))
172
- comps = np .asarray (comps )
173
172
if not is_list_like (values ):
174
173
raise TypeError ("only list-like objects are allowed to be passed"
175
174
" to isin(), you passed a "
176
175
"[{0}]" .format (type (values ).__name__ ))
177
- if not isinstance (values , np .ndarray ):
178
- values = list (values )
176
+
177
+
178
+ from pandas import DatetimeIndex , PeriodIndex
179
+
180
+ if needs_i8_conversion (comps ):
181
+ if is_period_dtype (values ):
182
+ values = PeriodIndex (values )
183
+ comps = PeriodIndex (comps )
184
+ else :
185
+ values = DatetimeIndex (values )
186
+ comps = DatetimeIndex (comps )
187
+
188
+ values = values .asi8
189
+ comps = comps .asi8
190
+ elif is_bool_dtype (comps ):
191
+ values = np .asarray (values ).view ('uint8' )
192
+ comps = np .asarray (comps ).view ('uint8' )
193
+ else :
194
+ values = np .asarray (values )
195
+ comps = np .asarray (comps )
179
196
180
197
# GH11232
181
198
# work-around for numpy < 1.8 and comparisions on py3
182
199
# faster for larger cases to use np.in1d
183
200
if (_np_version_under1p8 and compat .PY3 ) or len (comps ) > 1000000 :
184
201
f = lambda x , y : np .in1d (x , np .asarray (list (y )))
185
- else :
186
- f = lambda x , y : lib .ismember_int64 (x , set (y ))
187
-
188
- # may need i8 conversion for proper membership testing
189
- if is_datetime64_dtype (comps ):
190
- from pandas .tseries .tools import to_datetime
191
- values = to_datetime (values )._values .view ('i8' )
192
- comps = comps .view ('i8' )
193
- elif is_timedelta64_dtype (comps ):
194
- from pandas .tseries .timedeltas import to_timedelta
195
- values = to_timedelta (values )._values .view ('i8' )
196
- comps = comps .view ('i8' )
197
202
elif is_int64_dtype (comps ):
198
- pass
203
+ f = lambda x , y : lib . ismember_int64 ( x , set ( y ))
199
204
else :
200
205
f = lambda x , y : lib .ismember (x , set (values ))
201
206
0 commit comments