@@ -441,9 +441,9 @@ def resolve_iloc(self, ary):
441441 return SeriesIatType (ary )
442442
443443# PR135. This needs to be commented out
444- # def resolve_loc(self, ary):
445- # # TODO: support iat/iloc differences
446- # return SeriesIatType(ary)
444+ def resolve_loc (self , ary ):
445+ # TODO: support iat/iloc differences
446+ return SeriesIatType (ary )
447447
448448 # @bound_function("array.astype")
449449 # def resolve_astype(self, ary, args, kws):
@@ -900,14 +900,14 @@ def __init__(self, stype):
900900
901901
902902# PR135. This needs to be commented out
903- # @infer_global(operator.getitem)
904- # class GetItemSeriesIat(AbstractTemplate):
905- # key = operator.getitem
906- #
907- # def generic(self, args, kws):
908- # # iat[] is the same as regular getitem
909- # if isinstance(args[0], SeriesIatType):
910- # return GetItemSeries.generic(self, (args[0].stype, args[1]), kws)
903+ @infer_global (operator .getitem )
904+ class GetItemSeriesIat (AbstractTemplate ):
905+ key = operator .getitem
906+
907+ def generic (self , args , kws ):
908+ # iat[] is the same as regular getitem
909+ if isinstance (args [0 ], SeriesIatType ):
910+ return GetItemSeries .generic (self , (args [0 ].stype , args [1 ]), kws )
911911
912912
913913@infer
@@ -1033,110 +1033,110 @@ def generic_expand_cumulative_series(self, args, kws):
10331033 delattr (SeriesAttribute , attr )
10341034
10351035# PR135. This needs to be commented out
1036- # @infer_global(operator.getitem)
1037- # class GetItemSeries(AbstractTemplate):
1038- # key = operator.getitem
1039- #
1040- # def generic(self, args, kws):
1041- # assert not kws
1042- # [in_arr, in_idx] = args
1043- # is_arr_series = False
1044- # is_idx_series = False
1045- # is_arr_dt_index = False
1046- #
1047- # if not isinstance(in_arr, SeriesType) and not isinstance(in_idx, SeriesType):
1048- # return None
1049- #
1050- # if isinstance(in_arr, SeriesType):
1051- # in_arr = series_to_array_type(in_arr)
1052- # is_arr_series = True
1053- # if in_arr.dtype == types.NPDatetime('ns'):
1054- # is_arr_dt_index = True
1055- #
1056- # if isinstance(in_idx, SeriesType):
1057- # in_idx = series_to_array_type(in_idx)
1058- # is_idx_series = True
1059- #
1060- # # TODO: dt_index
1061- # if in_arr == string_array_type:
1062- # # XXX fails due in overload
1063- # # compile_internal version results in symbol not found!
1064- # # sig = self.context.resolve_function_type(
1065- # # operator.getitem, (in_arr, in_idx), kws)
1066- # # HACK to get avoid issues for now
1067- # if isinstance(in_idx, (types.Integer, types.IntegerLiteral)):
1068- # sig = string_type(in_arr, in_idx)
1069- # else:
1070- # sig = GetItemStringArray.generic(self, (in_arr, in_idx), kws)
1071- # elif in_arr == list_string_array_type:
1072- # # TODO: split view
1073- # # mimic array indexing for list
1074- # if (isinstance(in_idx, types.Array) and in_idx.ndim == 1
1075- # and isinstance(
1076- # in_idx.dtype, (types.Integer, types.Boolean))):
1077- # sig = signature(in_arr, in_arr, in_idx)
1078- # else:
1079- # sig = numba.typing.collections.GetItemSequence.generic(
1080- # self, (in_arr, in_idx), kws)
1081- # elif in_arr == string_array_split_view_type:
1082- # sig = GetItemStringArraySplitView.generic(
1083- # self, (in_arr, in_idx), kws)
1084- # else:
1085- # out = get_array_index_type(in_arr, in_idx)
1086- # sig = signature(out.result, in_arr, out.index)
1087- #
1088- # if sig is not None:
1089- # arg1 = sig.args[0]
1090- # arg2 = sig.args[1]
1091- # if is_arr_series:
1092- # sig.return_type = if_arr_to_series_type(sig.return_type)
1093- # arg1 = if_arr_to_series_type(arg1)
1094- # if is_idx_series:
1095- # arg2 = if_arr_to_series_type(arg2)
1096- # sig.args = (arg1, arg2)
1097- # # dt_index and Series(dt64) should return Timestamp
1098- # if is_arr_dt_index and sig.return_type == types.NPDatetime('ns'):
1099- # sig.return_type = pandas_timestamp_type
1100- # return sig
1101-
1036+ @infer_global (operator .getitem )
1037+ class GetItemSeries (AbstractTemplate ):
1038+ key = operator .getitem
11021039
1103- # @infer_global(operator.setitem)
1104- # class SetItemSeries(SetItemBuffer):
1105- # def generic(self, args, kws):
1106- # assert not kws
1107- # series, idx, val = args
1108- # if not isinstance(series, SeriesType):
1109- # return None
1110- # # TODO: handle any of args being Series independently
1111- # ary = series_to_array_type(series)
1112- # is_idx_series = False
1113- # if isinstance(idx, SeriesType):
1114- # idx = series_to_array_type(idx)
1115- # is_idx_series = True
1116- # is_val_series = False
1117- # if isinstance(val, SeriesType):
1118- # val = series_to_array_type(val)
1119- # is_val_series = True
1120- # # TODO: strings, dt_index
1121- # res = super(SetItemSeries, self).generic((ary, idx, val), kws)
1122- # if res is not None:
1123- # new_series = if_arr_to_series_type(res.args[0])
1124- # idx = res.args[1]
1125- # val = res.args[2]
1126- # if is_idx_series:
1127- # idx = if_arr_to_series_type(idx)
1128- # if is_val_series:
1129- # val = if_arr_to_series_type(val)
1130- # res.args = (new_series, idx, val)
1131- # return res
1132- #
1133- #
1134- # @infer_global(operator.setitem)
1135- # class SetItemSeriesIat(SetItemSeries):
1136- # def generic(self, args, kws):
1137- # # iat[] is the same as regular setitem
1138- # if isinstance(args[0], SeriesIatType):
1139- # return SetItemSeries.generic(self, (args[0].stype, args[1], args[2]), kws)
1040+ def generic (self , args , kws ):
1041+ assert not kws
1042+ [in_arr , in_idx ] = args
1043+ is_arr_series = False
1044+ is_idx_series = False
1045+ is_arr_dt_index = False
1046+
1047+ if not isinstance (in_arr , SeriesType ) and not isinstance (in_idx , SeriesType ):
1048+ return None
1049+
1050+ if isinstance (in_arr , SeriesType ):
1051+ in_arr = series_to_array_type (in_arr )
1052+ is_arr_series = True
1053+ if in_arr .dtype == types .NPDatetime ('ns' ):
1054+ is_arr_dt_index = True
1055+
1056+ if isinstance (in_idx , SeriesType ):
1057+ in_idx = series_to_array_type (in_idx )
1058+ is_idx_series = True
1059+
1060+ # TODO: dt_index
1061+ if in_arr == string_array_type :
1062+ # XXX fails due in overload
1063+ # compile_internal version results in symbol not found!
1064+ # sig = self.context.resolve_function_type(
1065+ # operator.getitem, (in_arr, in_idx), kws)
1066+ # HACK to get avoid issues for now
1067+ if isinstance (in_idx , (types .Integer , types .IntegerLiteral )):
1068+ sig = string_type (in_arr , in_idx )
1069+ else :
1070+ sig = GetItemStringArray .generic (self , (in_arr , in_idx ), kws )
1071+ elif in_arr == list_string_array_type :
1072+ # TODO: split view
1073+ # mimic array indexing for list
1074+ if (isinstance (in_idx , types .Array ) and in_idx .ndim == 1
1075+ and isinstance (
1076+ in_idx .dtype , (types .Integer , types .Boolean ))):
1077+ sig = signature (in_arr , in_arr , in_idx )
1078+ else :
1079+ sig = numba .typing .collections .GetItemSequence .generic (
1080+ self , (in_arr , in_idx ), kws )
1081+ elif in_arr == string_array_split_view_type :
1082+ sig = GetItemStringArraySplitView .generic (
1083+ self , (in_arr , in_idx ), kws )
1084+ else :
1085+ out = get_array_index_type (in_arr , in_idx )
1086+ sig = signature (out .result , in_arr , out .index )
1087+
1088+ if sig is not None :
1089+ arg1 = sig .args [0 ]
1090+ arg2 = sig .args [1 ]
1091+ if is_arr_series :
1092+ sig .return_type = if_arr_to_series_type (sig .return_type )
1093+ arg1 = if_arr_to_series_type (arg1 )
1094+ if is_idx_series :
1095+ arg2 = if_arr_to_series_type (arg2 )
1096+ sig .args = (arg1 , arg2 )
1097+ # dt_index and Series(dt64) should return Timestamp
1098+ if is_arr_dt_index and sig .return_type == types .NPDatetime ('ns' ):
1099+ sig .return_type = pandas_timestamp_type
1100+ return sig
1101+
1102+
1103+ @infer_global (operator .setitem )
1104+ class SetItemSeries (SetItemBuffer ):
1105+ def generic (self , args , kws ):
1106+ assert not kws
1107+ series , idx , val = args
1108+ if not isinstance (series , SeriesType ):
1109+ return None
1110+ # TODO: handle any of args being Series independently
1111+ ary = series_to_array_type (series )
1112+ is_idx_series = False
1113+ if isinstance (idx , SeriesType ):
1114+ idx = series_to_array_type (idx )
1115+ is_idx_series = True
1116+ is_val_series = False
1117+ if isinstance (val , SeriesType ):
1118+ val = series_to_array_type (val )
1119+ is_val_series = True
1120+ # TODO: strings, dt_index
1121+ res = super (SetItemSeries , self ).generic ((ary , idx , val ), kws )
1122+ if res is not None :
1123+ new_series = if_arr_to_series_type (res .args [0 ])
1124+ idx = res .args [1 ]
1125+ val = res .args [2 ]
1126+ if is_idx_series :
1127+ idx = if_arr_to_series_type (idx )
1128+ if is_val_series :
1129+ val = if_arr_to_series_type (val )
1130+ res .args = (new_series , idx , val )
1131+ return res
1132+
1133+
1134+ @infer_global (operator .setitem )
1135+ class SetItemSeriesIat (SetItemSeries ):
1136+ def generic (self , args , kws ):
1137+ # iat[] is the same as regular setitem
1138+ if isinstance (args [0 ], SeriesIatType ):
1139+ return SetItemSeries .generic (self , (args [0 ].stype , args [1 ], args [2 ]), kws )
11401140
11411141
11421142inplace_ops = [
0 commit comments