Add setitem#394
Conversation
|
Hello @Rubtsowa! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2019-12-27 07:02:08 UTC |
| Parameters | ||
| ---------- | ||
| series: :obj:`pandas.Series` | ||
| input series |
| pd.testing.assert_series_equal(A1, A2) | ||
|
|
||
| @skip_numba_jit | ||
| @skip_sdc_jit |
There was a problem hiding this comment.
Can we get the test passed instead of skipping this one?
| self.assertEqual(hpat_func(S), test_impl(S)) | ||
|
|
||
| @skip_numba_jit | ||
| @skip_sdc_jit |
There was a problem hiding this comment.
The same. It's not good idea to skip the tests.
| # series[0] = numb | ||
| # | ||
| # series[2:6] = numb | ||
| # | ||
| # indices = pd.Series(np.asarray([1, 6, 7, 8, 9])) | ||
| # series[indices] = numb |
There was a problem hiding this comment.
I would propose to add 3 examples: for num index, for slice, for series index. Then insert all the examples to docstring.
There was a problem hiding this comment.
Additionally let's initialize Series with 5 elements, I think 10 is too many, because the result takes much space in the docstring,
| if not isinstance(self, SeriesType): | ||
| raise TypingError('{} The object must be a pandas.series. Given: {}'.format(_func_name, self)) | ||
|
|
||
| ty_checker = TypeChecker('Operator setitem().') |
There was a problem hiding this comment.
Is it correct to use brackets for setitem()?
There was a problem hiding this comment.
This quite correctly. Operator getitem also uses.
There was a problem hiding this comment.
Is there other reasons that it is correct?
|
|
||
| return hpat_pandas_series_setitem_idx_series_impl | ||
|
|
||
| raise TypingError('{} The index must be an Integer, Slice or a pandas.series. Given: {}'.format(_func_name, idx)) |
There was a problem hiding this comment.
Moreover I would propose to use TypeCheker here.
| with self.assertRaises(TypingError) as raises: | ||
| hpat_func(S, ind2, value2) | ||
| msg = 'Operator setitem. The object idx' + '\n' + ' given: unicode_type' + '\n' + ' expected: int, Slice, Series' | ||
| msg = 'Operator setitem. The object idx' + '\n' + ' given: unicode_type' + '\n' \ |
There was a problem hiding this comment.
Why not avoid concatenation of string via +?
msg = 'Operator setitem. The object idx\n given: unicode_type\n expected: int, Slice, Series'
|
|
||
| with self.assertRaises(TypingError) as raises: | ||
| hpat_func(S, ind1, value1) | ||
| msg = 'Operator setitem. The object value' + '\n' + ' given: unicode_type' + '\n' + ' expected: self' |
There was a problem hiding this comment.
Why not avoid concatenation of string via +?
| with self.assertRaises(TypingError) as raises: | ||
| hpat_func(S, ind1, value1) | ||
| msg = 'Operator setitem. The object value' + '\n' + ' given: unicode_type' + '\n' + ' expected: self' | ||
| msg = 'Operator setitem. The object value\n given: unicode_type\n expected: self' |
There was a problem hiding this comment.
Let's create message template for code reusage:
msg_tmpl = 'Operator setitem. The object {}\n given: unicode_type\n expected: {}'
msg = msg_tmpl.format('value', 'self')
# ...
msg = msg_tmpl.format('idx', 'int, Slice, Series')
|
|
||
| if (isinstance(value, SeriesType) and not isinstance(self.dtype, value.dtype)) or \ | ||
| not isinstance(self.dtype, type(value)): | ||
| ty_checker.raise_exc(value, 'self', 'value') |
There was a problem hiding this comment.
What do you mean 'self'? What does mean self expected?
| numb = 0 | ||
| series = pd.Series(np.arange(5, 0, -1)) # Series of 5, 4, 3, 2, 1 | ||
|
|
||
| series[0] = numb |
There was a problem hiding this comment.
I think it'd be better to rename 'numb' to 'value' (since the former is a word itself)
| ************************************************* | ||
| Pandas Series operator :attr:`pandas.Series.set` implementation | ||
|
|
||
| Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_setitem_unsupported |
There was a problem hiding this comment.
Please use a correct line to run the tests for setitem, i.e.
python -m sdc.runtests -k sdc.tests.test_series.TestSeries.test_series_setitem*
| Parameters | ||
| ---------- | ||
| series: :obj:`pandas.Series` | ||
| input series |
There was a problem hiding this comment.
Please use the same indent
|
|
||
| return hpat_pandas_series_setitem_idx_series_impl | ||
|
|
||
| ty_checker.raise_exc(idx, 'int, Slice, Series', 'idx') |
There was a problem hiding this comment.
I think we should simply return None here, as this exception will not reach the end user anyway.
| msg = 'Method pct_change(). The object periods' | ||
| self.assertIn(msg, str(raises.exception)) | ||
|
|
||
| def test_series_setitem_for_value(self): |
There was a problem hiding this comment.
It seems that all three positive tests only cover integer series case, so floats and strings are not covered.
It would be good to add them too, you can write an aggregated test for diff data types/values, like here:
Line 2176 in abfa12b
kozlov-alexey
left a comment
There was a problem hiding this comment.
OK, let's merge this and deal with StringArray problems later.
| Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_setitem_for_value | ||
| Test: python -m sdc.runtests sdc.tests.test_series.TestSeries.test_series_setitem_for_slice | ||
| """ | ||
| self._data[idx] = value |
There was a problem hiding this comment.
OK, I think I now why it doesn't work for StringArrays - operator.setitem for StringArray expects the size of 'value' to be equal to the value of _data[idx]. Hence, you'll need special handling for string data.
No description provided.