Skip to content
This repository was archived by the owner on Feb 2, 2024. It is now read-only.

Add setitem#394

Merged
kozlov-alexey merged 41 commits intoIntelPython:masterfrom
Rubtsowa:add_setitem
Dec 27, 2019
Merged

Add setitem#394
kozlov-alexey merged 41 commits intoIntelPython:masterfrom
Rubtsowa:add_setitem

Conversation

@Rubtsowa
Copy link
Copy Markdown
Contributor

@Rubtsowa Rubtsowa commented Dec 9, 2019

No description provided.

@pep8speaks
Copy link
Copy Markdown

pep8speaks commented Dec 11, 2019

Hello @Rubtsowa! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 215:87: E502 the backslash is redundant between brackets

Comment last updated at 2019-12-27 07:02:08 UTC

Comment thread sdc/datatypes/hpat_pandas_series_functions.py Outdated
Comment thread sdc/datatypes/hpat_pandas_series_functions.py
Parameters
----------
series: :obj:`pandas.Series`
input series
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indentation.

Comment thread sdc/tests/test_series.py Outdated
pd.testing.assert_series_equal(A1, A2)

@skip_numba_jit
@skip_sdc_jit
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get the test passed instead of skipping this one?

Comment thread sdc/tests/test_series.py Outdated
self.assertEqual(hpat_func(S), test_impl(S))

@skip_numba_jit
@skip_sdc_jit
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same. It's not good idea to skip the tests.

Comment thread examples/series_setitem.py Outdated
Comment on lines +38 to +43
# series[0] = numb
#
# series[2:6] = numb
#
# indices = pd.Series(np.asarray([1, 6, 7, 8, 9]))
# series[indices] = numb
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to add 3 examples: for num index, for slice, for series index. Then insert all the examples to docstring.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to use brackets for setitem()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This quite correctly. Operator getitem also uses.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover I would propose to use TypeCheker here.

Comment thread sdc/tests/test_series.py Outdated
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' \
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not avoid concatenation of string via +?
msg = 'Operator setitem. The object idx\n given: unicode_type\n expected: int, Slice, Series'

Comment thread sdc/tests/test_series.py Outdated

with self.assertRaises(TypingError) as raises:
hpat_func(S, ind1, value1)
msg = 'Operator setitem. The object value' + '\n' + ' given: unicode_type' + '\n' + ' expected: self'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not avoid concatenation of string via +?

Comment thread sdc/tests/test_series.py Outdated
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'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean 'self'? What does mean self expected?

@Rubtsowa Rubtsowa requested a review from akharche December 25, 2019 08:06
@Rubtsowa Rubtsowa removed the request for review from shssf December 25, 2019 08:48
Comment thread examples/series_setitem_int.py Outdated
numb = 0
series = pd.Series(np.arange(5, 0, -1)) # Series of 5, 4, 3, 2, 1

series[0] = numb
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the same indent

Comment thread sdc/datatypes/hpat_pandas_series_functions.py

return hpat_pandas_series_setitem_idx_series_impl

ty_checker.raise_exc(idx, 'int, Slice, Series', 'idx')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should simply return None here, as this exception will not reach the end user anyway.

Comment thread sdc/tests/test_series.py Outdated
msg = 'Method pct_change(). The object periods'
self.assertIn(msg, str(raises.exception))

def test_series_setitem_for_value(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

for data in data_to_test:

Copy link
Copy Markdown
Contributor

@kozlov-alexey kozlov-alexey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kozlov-alexey kozlov-alexey merged commit ab559d9 into IntelPython:master Dec 27, 2019
@Rubtsowa Rubtsowa deleted the add_setitem branch April 7, 2020 07:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants