This repository was archived by the owner on Mar 1, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathhpat_pandas_series_functions.py
More file actions
1955 lines (1450 loc) · 64.7 KB
/
Copy pathhpat_pandas_series_functions.py
File metadata and controls
1955 lines (1450 loc) · 64.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# *****************************************************************************
# Copyright (c) 2019, Intel Corporation All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************
"""
| :class:`pandas.Series` functions and operators implementations in HPAT
| Also, it contains Numba internal operators which are required for Series type handling
"""
import numpy
import operator
import pandas
from numba.errors import TypingError
from numba.extending import (types, overload, overload_method, overload_attribute)
from numba import types
import hpat
from hpat.hiframes.pd_series_ext import SeriesType
from hpat.str_arr_ext import StringArrayType
from hpat.utils import to_array
@overload(operator.getitem)
def hpat_pandas_series_getitem(self, idx):
"""
Pandas Series operator :attr:`pandas.Series.get` implementation
**Algorithm**: result = series[idx]
**Test**: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_static_getitem_series1
Parameters
----------
series: :obj:`pandas.Series`
input series
idx: :obj:`int`, :obj:`slice` or :obj:`pandas.Series`
input index
Returns
-------
:class:`pandas.Series` or an element of the underneath type
object of :class:`pandas.Series`
"""
_func_name = 'Operator getitem().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if isinstance(idx, types.Integer):
def hpat_pandas_series_getitem_idx_integer_impl(self, idx):
"""
**Test**: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_iloc1
"""
result = self._data[idx]
return result
return hpat_pandas_series_getitem_idx_integer_impl
if isinstance(idx, types.SliceType):
def hpat_pandas_series_getitem_idx_slice_impl(self, idx):
"""
**Test**: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_iloc2
"""
result = pandas.Series(self._data[idx])
return result
return hpat_pandas_series_getitem_idx_slice_impl
if isinstance(idx, SeriesType):
def hpat_pandas_series_getitem_idx_series_impl(self, idx):
"""
**Test**: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_setitem_series_bool2
"""
super_index = idx._data
result = self._data[super_index]
return result
return hpat_pandas_series_getitem_idx_series_impl
raise TypingError('{} The index must be an Integer, Slice or a pandas.series. Given: {}'.format(_func_name, idx))
@overload_attribute(SeriesType, 'at')
@overload_attribute(SeriesType, 'iat')
@overload_attribute(SeriesType, 'iloc')
@overload_attribute(SeriesType, 'loc')
def hpat_pandas_series_iloc(self):
"""
Pandas Series operators :attr:`pandas.Series.at`, :attr:`pandas.Series.iat`, :attr:`pandas.Series.iloc`, :attr:`pandas.Series.loc` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_iloc2
Parameters
----------
series: :class:`pandas.Series`
input series
Returns
-------
:obj:`pandas.Series`
returns an object of :obj:`pandas.Series`
"""
_func_name = 'Operator at/iat/iloc/loc().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_iloc_impl(self):
return self
return hpat_pandas_series_iloc_impl
@overload_attribute(SeriesType, 'shape')
def hpat_pandas_series_shape(self):
"""
Pandas Series attribute :attr:`pandas.Series.shape` implementation
**Algorithm**: result = series.shape
**Test**: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_shape1
Parameters
----------
series: :obj:`pandas.Series`
input series
Returns
-------
:obj:`tuple`
a tuple of the shape of the underlying data
"""
_func_name = 'Attribute shape.'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_shape_impl(self):
return self._data.shape
return hpat_pandas_series_shape_impl
@overload_attribute(SeriesType, 'values')
def hpat_pandas_series_iloc(self):
"""
Pandas Series attribute 'values' implementation.
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.values.html#pandas.Series.values
Algorithm: result = series.values
Where:
series: pandas.series
result: pandas.series as ndarray
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_values
"""
_func_name = 'Attribute values.'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_values_impl(self):
return self._data
return hpat_pandas_series_values_impl
@overload_attribute(SeriesType, 'index')
def hpat_pandas_series_index(self):
"""
Pandas Series attribute :attr:`pandas.Series.index` implementation
**Algorithm**: result = series.index
**Test**: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_index1
python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_index2
Parameters
----------
series: :obj:`pandas.Series`
input series
Returns
-------
:class:`pandas.Series`
the index of the Series
"""
_func_name = 'Attribute index.'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_index_impl(self):
return self._index
return hpat_pandas_series_index_impl
@overload_attribute(SeriesType, 'size')
def hpat_pandas_series_size(self):
"""
Pandas Series attribute :attr:`pandas.Series.size` implementation
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_size
Parameters
----------
series: :obj:`pandas.Series`
input series
Returns
-------
:class:`pandas.Series`
Return the number of elements in the underlying data.
"""
_func_name = 'Attribute size.'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_size_impl(self):
return len(self._data)
return hpat_pandas_series_size_impl
@overload_attribute(SeriesType, 'ndim')
def hpat_pandas_series_ndim(self):
"""
Pandas Series attribute :attr:`pandas.Series.ndim` implementation
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_getattr_ndim
Parameters
----------
self: :obj:`pandas.Series`
input series
Returns
-------
:obj:`int`
Number of dimensions of the underlying data, by definition 1
"""
_func_name = 'Attribute ndim.'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_ndim_impl(self):
return 1
return hpat_pandas_series_ndim_impl
@overload_attribute(SeriesType, 'T')
def hpat_pandas_series_T(self):
"""
Pandas Series attribute :attr:`pandas.Series.T` implementation
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_getattr_T
Parameters
----------
self: :obj:`pandas.Series`
input series
Returns
-------
:obj:`numpy.ndarray`
An array representing the underlying data
"""
_func_name = 'Attribute T.'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_T_impl(self):
return self._data
return hpat_pandas_series_T_impl
@overload(len)
def hpat_pandas_series_len(self):
"""
Pandas Series operator :func:`len` implementation
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_len
Parameters
----------
series: :class:`pandas.Series`
Returns
-------
:obj:`int`
number of items in the object
"""
_func_name = 'Operator len().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
def hpat_pandas_series_len_impl(self):
return len(self._data)
return hpat_pandas_series_len_impl
@overload_method(SeriesType, 'shift')
def hpat_pandas_series_shift(self, periods=1, freq=None, axis=0, fill_value=None):
"""
Pandas Series method :meth:`pandas.Series.shift` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_shift
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_shift_unboxing
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_shift_full
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_shift_str
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_shift_fill_str
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_shift_unsupported_params
Parameters
----------
self: :obj:`pandas.Series`
input series
periods: :obj:`int`
Number of periods to shift. Can be positive or negative.
freq: :obj:`DateOffset`, :obj:`tseries.offsets`, :obj:`timedelta`, :obj:`str`
Offset to use from the tseries module or time rule (e.g. ‘EOM’).
*unsupported*
axis: :obj:`int`, :obj:`str`
Axis along which the operation acts
0/None/'index' - row-wise operation
1/'columns' - column-wise operation
*unsupported*
fill_value : :obj:`int`, :obj:`float`
The scalar value to use for newly introduced missing values.
Returns
-------
:obj:`scalar`
returns :obj:`series` object
"""
_func_name = 'Method shift().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if not isinstance(self.data.dtype, types.Number):
msg = '{} The object must be a number. Given self.data.dtype: {}'
raise TypingError(msg.format(_func_name, self.data.dtype))
if not isinstance(fill_value, (types.Omitted, types.Number, types.NoneType)) and fill_value is not None:
raise TypingError('{} The object must be a number. Given fill_value: {}'.format(_func_name, fill_value))
if not isinstance(freq, (types.Omitted, types.NoneType)) and freq is not None:
raise TypingError('{} Unsupported parameters. Given freq: {}'.format(_func_name, freq))
if not isinstance(axis, (types.Omitted, int, types.Integer)):
raise TypingError('{} Unsupported parameters. Given axis: {}'.format(_func_name, axis))
def hpat_pandas_series_shift_impl(self, periods=1, freq=None, axis=0, fill_value=None):
if axis != 0:
raise TypingError('Method shift(). Unsupported parameters. Given axis != 0')
arr = numpy.empty_like(self._data)
if periods > 0:
arr[:periods] = fill_value or numpy.nan
arr[periods:] = self._data[:-periods]
elif periods < 0:
arr[periods:] = fill_value or numpy.nan
arr[:periods] = self._data[-periods:]
else:
arr[:] = self._data
return pandas.Series(arr)
return hpat_pandas_series_shift_impl
@overload_method(SeriesType, 'isin')
def hpat_pandas_series_isin(self, values):
"""
Pandas Series method :meth:`pandas.Series.isin` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_isin_list1
Parameters
-----------
values : :obj:`list` or :obj:`set` object
specifies values to look for in the series
Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object indicating if each element of self is in values
"""
_func_name = 'Method isin().'
if not isinstance(self, SeriesType):
raise TypingError(
'{} The object must be a pandas.series. Given self: {}'.format(_func_name, self))
if not isinstance(values, (types.Set, types.List)):
raise TypingError(
'{} The argument must be set or list-like object. Given values: {}'.format(_func_name, values))
def hpat_pandas_series_isin_impl(self, values):
# TODO: replace with below line when Numba supports np.isin in nopython mode
# return pandas.Series(np.isin(self._data, values))
return pandas.Series([(x in values) for x in self._data])
return hpat_pandas_series_isin_impl
@overload_method(SeriesType, 'append')
def hpat_pandas_series_append(self, to_append):
"""
Pandas Series method :meth:`pandas.Series.append` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_append1
Parameters
-----------
to_append : :obj:`pandas.Series` object
input argument
ignore_index:
*unsupported*
verify_integrity:
*unsupported*
Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object
"""
_func_name = 'Method append().'
if not isinstance(self, SeriesType) or not isinstance(to_append, SeriesType):
raise TypingError(
'{} The object must be a pandas.series. Given self: {}, to_append: {}'.format(_func_name, self, to_append))
def hpat_pandas_series_append_impl(self, to_append):
return pandas.Series(self._data + to_append._data)
return hpat_pandas_series_append_impl
@overload_method(SeriesType, 'copy')
def hpat_pandas_series_copy(self, deep=True):
"""
Pandas Series method :meth:`pandas.Series.copy` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_copy_str1
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_copy_int1
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_copy_deep
Parameters
-----------
self: :class:`pandas.Series`
input arg
deep: :obj:`bool`, default :obj:`True`
Make a deep copy, including a copy of the data and the indices.
With deep=False neither the indices nor the data are copied.
[HPAT limitations]:
- deep=False: shallow copy of index is not supported
Returns
-------
:obj:`pandas.Series` or :obj:`pandas.DataFrame`
Object type matches caller.
"""
_func_name = 'Method Series.copy().'
if (isinstance(self, SeriesType) and
(isinstance(deep, (types.Omitted, types.Boolean)) or deep == True)
):
if isinstance(self.index, types.NoneType):
def hpat_pandas_series_copy_impl(self, deep=True):
if deep:
return pandas.Series(self._data.copy())
else:
return pandas.Series(self._data)
return hpat_pandas_series_copy_impl
else:
def hpat_pandas_series_copy_impl(self, deep=True):
if deep:
return pandas.Series(self._data.copy(), index=self._index.copy())
else:
return pandas.Series(self._data, index=self._index.copy())
return hpat_pandas_series_copy_impl
@overload_method(SeriesType, 'groupby')
def hpat_pandas_series_groupby(
self,
by=None,
axis=0,
level=None,
as_index=True,
sort=True,
group_keys=True,
squeeze=False,
observed=False):
"""
Pandas Series method :meth:`pandas.Series.groupby` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_groupby_count
Parameters
-----------
self: :class:`pandas.Series`
input arg
by: :obj:`pandas.Series` object
Used to determine the groups for the groupby
axis:
*unsupported*
level:
*unsupported*
as_index:
*unsupported*
sort:
*unsupported*
group_keys:
*unsupported*
squeeze:
*unsupported*
observed:
*unsupported*
Returns
-------
:obj:`pandas.SeriesGroupBy`
returns :obj:`pandas.SeriesGroupBy` object
"""
_func_name = 'Method Series.groupby().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if by is None and axis is None:
raise TypingError("{} You have to supply one of 'by' or 'axis' parameters".format(_func_name))
if level is not None and not isinstance(level, (types.Integer, types.NoneType, types.Omitted)):
raise TypingError("{} 'level' must be an Integer. Given: {}".format(_func_name, level))
def hpat_pandas_series_groupby_impl(
self,
by=None,
axis=0,
level=None,
as_index=True,
sort=True,
group_keys=True,
squeeze=False,
observed=False):
# TODO Needs to implement parameters value check
# if level is not None and (level < -1 or level > 0):
# raise ValueError("Method Series.groupby(). level > 0 or level < -1 only valid with MultiIndex")
return pandas.core.groupby.SeriesGroupBy(self)
return hpat_pandas_series_groupby_impl
@overload_method(SeriesType, 'isna')
def hpat_pandas_series_isna(self):
"""
Pandas Series method :meth:`pandas.Series.isna` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_isna1
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_str_isna1
Parameters
-----------
self : :obj:`pandas.Series` object
input argument
Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object
"""
_func_name = 'Method isna().'
if not isinstance(self, SeriesType):
raise TypingError(
'{} The object must be a pandas.series. Given self: {}'.format(_func_name, self))
if isinstance(self.dtype, (types.Integer, types.Float)):
def hpat_pandas_series_isna_impl(self):
return pandas.Series(numpy.isnan(self._data))
return hpat_pandas_series_isna_impl
if isinstance(self.dtype, types.UnicodeType):
def hpat_pandas_series_isna_impl(self):
result = numpy.empty(len(self._data), numpy.bool_)
byte_size = 8
# iterate over bits in StringArrayType null_bitmap and fill array indicating if array's element are NaN
for i in range(len(self._data)):
bmap_idx = i // byte_size
bit_idx = i % byte_size
bmap = self._data.null_bitmap[bmap_idx]
bit_value = (bmap >> bit_idx) & 1
result[i] = bit_value == 0
return pandas.Series(result)
return hpat_pandas_series_isna_impl
@overload_method(SeriesType, 'ne')
def hpat_pandas_series_ne(self, other, level=None, fill_value=None, axis=0):
"""
Pandas Series method :meth:`pandas.Series.ne` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op8
Parameters
----------
self: :class:`pandas.Series`
input arg
other: :obj:`pandas.Series`, :obj:`int` or :obj:`float`
input arg
level: :obj:`int` or name
*unsupported*
fill_value: :obj:`float` or None, default None
*unsupported*
axis: default 0
*unsupported*
Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object
"""
_func_name = 'Method ne().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if level is not None or fill_value is not None or axis != 0:
raise TypingError('{} Unsupported parameters. Given level: {}, fill_value: {}, axis: {}'.format(_func_name, level, fill_value, axis))
if isinstance(other, SeriesType):
def hpat_pandas_series_ne_impl(self, other):
"""
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op8
"""
return pandas.Series(self._data != other._data)
return hpat_pandas_series_ne_impl
if isinstance(other, types.Integer) or isinstance(other, types.Float):
def hpat_pandas_series_ne_impl(self, other):
"""
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op8_integer_scalar
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op8_float_scalar
"""
return pandas.Series(self._data != other)
return hpat_pandas_series_ne_impl
raise TypingError('{} The object must be a pandas.series and argument must be a number. Given: {} and other: {}'.format(_func_name, self, other))
@overload_method(SeriesType, 'add')
def hpat_pandas_series_add(self, other, level=None, fill_value=None, axis=0):
"""
Pandas Series method :meth:`pandas.Series.add` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5
Parameters
----------
self: :class:`pandas.Series`
input arg
other: :obj:`pandas.Series`, :obj:`int` or :obj:`float`
input arg
level: :obj:`int` or name
*unsupported*
fill_value: :obj:`float` or None, default None
*unsupported*
axis: default 0
*unsupported*
Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object
"""
_func_name = 'Method add().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if level is not None or fill_value is not None or axis != 0:
raise TypingError('{} Unsupported parameters. Given level: {}, fill_value: {}, axis: {}'.format(_func_name, level, fill_value, axis))
if isinstance(other, SeriesType):
def hpat_pandas_series_add_impl(lhs, rhs):
"""
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5
"""
return pandas.Series(lhs._data + rhs._data)
return hpat_pandas_series_add_impl
if isinstance(other, types.Integer) or isinstance(other, types.Float):
def hpat_pandas_series_add_number_impl(lhs, rhs):
"""
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5_integer_scalar
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5_float_scalar
"""
return pandas.Series(lhs._data + rhs)
return hpat_pandas_series_add_number_impl
raise TypingError('{} The object must be a pandas.series and argument must be a number. Given: {} and other: {}'.format(_func_name, self, other))
@overload_method(SeriesType, 'sub')
def hpat_pandas_series_sub(self, other, level=None, fill_value=None, axis=0):
"""
Pandas Series method :meth:`pandas.Series.sub` implementation.
.. only:: developer
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5
Parameters
----------
self: :class:`pandas.Series`
input arg
other: :obj:`pandas.Series`, :obj:`int` or :obj:`float`
input arg
level: :obj:`int` or name
*unsupported*
fill_value: :obj:`float` or None, default None
*unsupported*
axis: default 0
*unsupported*
Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object
"""
_func_name = 'Method sub().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if level is not None or fill_value is not None or axis != 0:
raise TypingError('{} Unsupported parameters. Given level: {}, fill_value: {}, axis: {}'.format(_func_name, level, fill_value, axis))
if isinstance(other, SeriesType):
def hpat_pandas_series_sub_impl(self, other):
"""
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5
"""
return pandas.Series(self._data - other._data)
return hpat_pandas_series_sub_impl
if isinstance(other, types.Integer) or isinstance(other, types.Float):
def hpat_pandas_series_sub_number_impl(self, other):
"""
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5_integer_scalar
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_op5_float_scalar
"""
return pandas.Series(self._data - other)
return hpat_pandas_series_sub_number_impl
raise TypingError('{} The object must be a pandas.series or scalar. Given other: {}'.format(_func_name, other))
@overload_method(SeriesType, 'sum')
def hpat_pandas_series_sum(
self,
axis=None,
skipna=None,
level=None,
numeric_only=None,
min_count=0,
):
"""
Pandas Series method :meth:`pandas.Series.sum` implementation.
.. only:: developer
Tests:
python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_sum1
# python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_sum2
Parameters
----------
self: :class:`pandas.Series`
input series
axis:
*unsupported*
skipna: :obj:`bool`, default :obj:`True`
Exclude NA/null values when computing the result.
level:
*unsupported*
numeric_only:
*unsupported*
min_count:
*unsupported*
Returns
-------
:obj:`float`
scalar or Series (if level specified)
"""
_func_name = 'Method sum().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if not (isinstance(axis, (types.Integer, types.Omitted)) or axis == None):
raise TypingError('{} The axis must be an Integer. Currently unsupported. Given: {}'.format(_func_name, axis))
if not (isinstance(skipna, (types.Boolean, types.Omitted)) or skipna == None):
raise TypingError('{} The skipna must be a Boolean. Given: {}'.format(_func_name, skipna))
if not (isinstance(level, (types.Integer, types.StringLiteral, types.Omitted)) or level == None):
raise TypingError('{} The level must be an Integer or level name. Currently unsupported. Given: {}'.format(_func_name, level))
if not (isinstance(numeric_only, (types.Boolean, types.Omitted)) or numeric_only == None):
raise TypingError('{} The numeric_only must be a Boolean. Currently unsupported. Given: {}'.format(_func_name, numeric_only))
if not (isinstance(min_count, (types.Integer, types.Omitted)) or min_count == 0):
raise TypingError('{} The min_count must be an Integer. Currently unsupported. Given: {}'.format(_func_name, min_count))
def hpat_pandas_series_sum_impl(
self,
axis=None,
skipna=None,
level=None,
numeric_only=None,
min_count=0,
):
"""
Test: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_sum1
"""
if skipna is None:
skipna = True
if skipna:
return numpy.nansum(self._data)
return numpy.sum(self._data)
return hpat_pandas_series_sum_impl
@overload_method(SeriesType, 'take')
def hpat_pandas_series_take(self, indices, axis=0, is_copy=False):
"""
Pandas Series method :meth:`pandas.Series.take` implementation.
.. only:: developer
Tests: python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_take_index_default
python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_take_index_default_unboxing
python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_take_index_int
python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_take_index_int_unboxing
python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_take_index_str
python -m hpat.runtests hpat.tests.test_series.TestSeries.test_series_take_index_str_unboxing
Parameters
----------
self: :obj:`pandas.Series`
input series
indices: :obj:`array-like`
An array of ints indicating which positions to take
axis: {0 or `index`, 1 or `columns`, None}, default 0
The axis on which to select elements. 0 means that we are selecting rows,
1 means that we are selecting columns.
*unsupported*
is_copy: :obj:`bool`, default True
Whether to return a copy of the original object or not.
*unsupported*
Returns
-------
:obj:`pandas.Series`
returns :obj:`pandas.Series` object containing the elements taken from the object
"""
_func_name = 'Method take().'
if not isinstance(self, SeriesType):
raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self))
if not isinstance(indices, types.List):
raise TypingError('{} The indices must be a List. Given: {}'.format(_func_name, indices))
if not (isinstance(axis, (types.Integer, types.Omitted)) or axis == 0):
raise TypingError('{} The axis must be an Integer. Currently unsupported. Given: {}'.format(_func_name, axis))
if not (isinstance(is_copy, (types.Boolean, types.Omitted)) or is_copy == False):
raise TypingError('{} The is_copy must be a boolean. Given: {}'.format(_func_name, is_copy))
if self.index is not types.none:
def hpat_pandas_series_take_impl(self, indices, axis=0, is_copy=False):
local_data = [self._data[i] for i in indices]
local_index = [self._index[i] for i in indices]
return pandas.Series(local_data, local_index)
return hpat_pandas_series_take_impl
else:
def hpat_pandas_series_take_noindex_impl(self, indices, axis=0, is_copy=False):
local_data = [self._data[i] for i in indices]
return pandas.Series(local_data, indices)
return hpat_pandas_series_take_noindex_impl