8000 Series.add / Series.lt with fill_value by 1e-to · Pull Request #655 · IntelPython/sdc · GitHub
[go: up one dir, main page]

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

Series.add / Series.lt with fill_value #655

Merged
merged 22 commits into from
Apr 23, 2020

Conversation

1e-to
Copy link
Contributor
@1e-to 1e-to commented Feb 28, 2020

No description provided.

@1e-to 1e-to requested a review from kozlov-alexey February 28, 2020 15:26
@pep8speaks
Copy link
pep8speaks commented Mar 2, 2020

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

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2020-04-14 15:20:52 UTC

@AlexanderKalistratov
Copy link
Collaborator

@kozlov-alexey ?

Comment on lines 2554 to 2556
fill_value_is_none = False
if isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None:
fill_value_is_none = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just:
fill_value_is_none = isinstance(fill_value, (types.NoneType, types.Omitted)) or fill_value is None
?

@@ -531,7 +531,7 @@ def sdc_fillna_inplace_int_impl(self, inplace=False, value=None):

def sdc_fillna_inplace_float_impl(self, inplace=False, value=None):
length = len(self)
for i in prange(length):
for i in range(length):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you reverting back to non scalable implementation?

@@ -1482,7 +1482,7 @@ def test_series_op5(self):

@skip_parallel
def test_series_op5_integer_scalar(self):
arithmetic_methods = ('add', 'sub', 'mul', 'div', 'truediv', 'floordiv', 'mod', 'pow')
arithmetic_methods = ('sub', 'mul', 'div', 'truediv', 'floordiv', 'mod', 'pow')
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you should remove this function from the test (this use case is still valid), instead you can add a check_dtype=False param to assert_series_equal function and add a comment to state why it's used.

Comment on lines 3578 to 3584
for data in cases_data:
for index in cases_index:
for scalar in cases_scalar:
for value in cases_value:
with self.subTest(data=data, index=index, scalar=scalar, value=value):
S1 = pd.Series(data, index)
pd.testing.assert_series_equal(sdc_func(S1, scalar, value), test_impl(S1, scalar, value))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use product instead of nested for-loops:

  for data, index, scalar, fill_value in product(cases_data, cases_index, cases_scalar, cases_value):
         S1 = pd.Series(data, index)
         with self.subTest(data=data, index=index, scalar=scalar, value=fill_value):
             result = sdc_func(S1, scalar, fill_value)
             resutl_ref = test_impl(S1, scalar, fill_value)
             pd.testing.assert_series_equal(result, resutl_ref)

S1 = pd.Series(data, index)
pd.testing.assert_series_equal(sdc_func(S1, scalar, value), test_impl(S1, scalar, value))

def test_series_lt(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of these tests should reflect that you're testing fill_value param, and now it fits to default use-case when all args are omitted more.

S2 = pd.Series(data, index2)
pd.testing.assert_series_equal(sdc_func(S1, S2), test_impl(S1, S2))

@unittest.skip('SDC returns only float Series')
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally it's no good to add some functionality and keep tests for it skipped, so the same comment as above: used check_dtype=False.

Comment on lines 3528 to 3529
S1 = pd.Series(data, index)
S2 = pd.Series(index, data)
Copy link
Contributor
@kozlov-alexey kozlov-alexey Mar 11, 2020

Choose a reason for hiding this comment

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

Hmm, this uses data as index for other series... This doesn't seem very transparent from functional coverage point of view. For instance, you test case when S2 has index=[3.3, 5.4, np.nan, 7.9, np.nan] but it won't be S1's index, so alignment of float indexes with NaNs is not tested. I would advice separate tests per different branches in impl, so e.g. if you have separate branch for S1.index=None and S2.index=None test it in a separate test. And for indexes you can just use:
for index1, index2 in product(cases_index, cases_index):

Comment on lines 4165 to 4170
fill_value_is_nan = False
if fill_value is None:
fill_value = numpy.nan
if not fill_value_is_none == True: # noqa
fill_value_is_nan = numpy.isnan(fill_value)
if not (fill_value_is_nan or fill_value_is_none == True): # noqa
Copy link
Contributor

Choose a reason for hiding this comment

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

You do not need to capture fill_value_is_none as compile time constant, as there's no need to eliminate dead branches here. If all you need is to run fillna when fill_value is not None/np.nan, you can just write:

            if (fill_value is not None and not numpy.isnan(fill_value)):
                numpy_like.fillna(self._data, inplace=True, value=fill_value)

if not fill_value_is_none == True: # noqa
fill_value_is_nan = numpy.isnan(fill_value)
if not (fill_value_is_nan or fill_value_is_none == True): # noqa
if (fill_value is not None and not numpy.isnan(fill_value)):
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you like the shorter form?

Suggested change
if (fill_value is not None and not numpy.isnan(fill_value)):
if not (fill_value is None or numpy.isnan(fill_value)):

Comment on lines 66 to 68
.. note::

Parameter axis is currently unsupported by Intel Scalable Dataframe Compiler
Copy link
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 have it here? Shouldn't it be one of unsupported parameters in limitations?


Limitations
-----------
- Parameters level, fill_value are currently unsupported by Intel Scalable Dataframe Compiler
Copy link
Contributor

Choose a reason for hiding this comment

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

You are adding support for fill_value

Given: self={}, other={}'.format(_func_name, self, other))

def sdc_pandas_series_operator_binop_impl(self, other):
return sdc_pandas_series_binop(self, other)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not

Suggested change
return sdc_pandas_series_binop(self, other)
return self.binop(other)

elena.totmenina added 2 commits March 21, 2020 13:27
cases_value = [None, 4, 5.5]
for data, index, value in product(cases_data, cases_index, cases_value):
with self.subTest(data=data, index=index, value=value):
S1 = pd.Series(data, index)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems corruption/compilation failure problems in tests are caused by using index=None as a data in S2 series. I'm still suggesting to not mix up data and indexes to be tested between each other, e.g.:

        for value in cases_value:
            for data1, data2 in product(cases_data, cases_data):
                for index1, index2 in product(cases_index, cases_index):
                    S1 = pd.Series(data1, index1)
                    S2 = pd.Series(data2, index2)
                    with self.subTest(left=S1, right=S2, value=value):
...


_func_name = 'Operator add().'
Copy link
Contributor

Choose a reason for hiding this comment

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

_func_name will not be defined in the function, and it's used in error-handling branches.

@AlexanderKalistratov
Copy link
Collaborator

@kozlov-alexey can we merge this?

template_series_arithmetic_binop = inspect.getsource(templates_module.sdc_pandas_series_binop)
template_series_comparison_binop = inspect.getsource(templates_module.sdc_pandas_series_comp_binop)
template_series_arithmetic_binop_operator = inspect.getsource(templates_module.sdc_pandas_series_operator_binop)
template_series_comparison_binop_operator = series_operator_comp_binop
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't the template_series_comparison_binop_operator be assigned inspect.getsource(...)?
I tried to run autogen_source_methos.py but got the following:

(SDC_MASTER) C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat>python buil
dscripts\autogen_sources_methods.py
c:\users\akozlov\appdata\local\continuum\anaconda3\hpat\sdc\utilities\utils.py:4
59: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  if init_vals is not ():
Exception of type AttributeError: 'function' object has no attribute 'replace'
while writing to a file: C:\Users\akozlov\AppData\Local\Continuum\anaconda3\hpat
\sdc\sdc_autogenerated.py

# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# *****************************************************************************
'''

Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need a different file - autogen_source_methods.py? And why we need to keep the old file - autogen_sources.py then?

@@ -116,9 +117,12 @@
imports_start_line, import_end_line = min(imports_line_numbers), max(imports_line_numbers)
import_section_text = ''.join(module_text_lines[imports_start_line: import_end_line + 1])

series_operator_comp_binop = inspect.getsource(templates_module.sdc_pandas_series_operator_comp_binop)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think series_operator_comp_binop var is needed, since we are using it only once.
Let's maybe rename and shorten the template names, e.g:

template_series_arithmetic_binop -> template_series_binop
template_series_comparison_binop -> template_series_comp_binop
template_series_arithmetic_binop_operator -> template_series_operator
template_series_comparison_binop_operator -> template_series_comp_operator
template_str_arr_comparison_binop -> template_str_arr_comp_binop

@AlexanderKalistratov AlexanderKalistratov merged commit 6d77677 into IntelPython:master Apr 23, 2020
akharche added a commit that referenced this pull request May 15, 2020
* Df.at impl (#738)

* Series.add / Series.lt with fill_value (#655)

* Impl Series.skew() (#813)

* Run tests in separate processes (#833)

* Run tests in separate processes

* Take tests list from sdc/tests/__init__.py

* change README (#818)

* change README

* change README for doc

* add refs

* change ref

* change ref

* change ref

* change readme

* Improve boxing (#832)

* Specify sdc version from channel for examples testing (#837)

* Specify sdc version from channel for examples testing

It occurs that conda resolver can take Intel SDC package
not from first channel where it is found.
Specify particular SDC version to avoid this in examples
for now.
Also print info for environment creation and package installing

* Fix incerrectly used f-string

* Fix log_info call

* Numba 0.49.0 all (#824)

* Fix run tests

Remove import of _getitem_array1d

* expectedFailure

* expectedFailure-2

* expectedFailure-3

* Conda recipe numba==0.49

* expectedFailure-4

* Refactor imports from Numba

* Unskip tests

* Fix using of numpy_support.from_dtype()

* Unskip tests

* Fix DataFrame tests with rewrite IR without Del statements

* Unskip tests

* Fix corr_overload with type inference error for none < 1

* Fix hpat_pandas_series_cov with type inference error for none < 2

* Unskip tests

* Unskip tests

* Fixed iternext_series_array with using _getitem_array1d.

_getitem_array1d is replaced with _getitem_array_single_int in Numba 0.49.

* Unskip tests

* Unskip old test

* Fix Series.at

* Unskip tests

* Add decrefs in boxing (#836)

* Adding extension type for pd.RangeIndex (#820)

* Adding extension type for pd.RangeIndex

This commit adds Numba extension types for pandas.RangeIndex class,
allowing creation of pd.RangeIndex objects and passing and returning them
to/from nopython functions.

* Applying review comments

* Fix for PR 831 (#839)

* Update pyarrow version to 0.17.0

Update recipe, code and docs.

* Disable intel channel

* Disable intel channel for testing

* Fix remarks

Co-authored-by: Vyacheslav Smirnov <vyacheslav.s.smirnov@intel.com>

* Update to Numba 0.49.1 (#838)

* Update to Numba 0.49.1

* Fix requirements.txt

* Add travis

Co-authored-by: Elena Totmenina <totmeninal@mail.ru>
Co-authored-by: Rubtsowa <36762665+Rubtsowa@users.noreply.github.com>
Co-authored-by: Sergey Pokhodenko <sergey.pokhodenko@intel.com>
Co-authored-by: Vyacheslav-Smirnov <51660067+Vyacheslav-Smirnov@users.noreply.github.com>
Co-authored-by: Alexey Kozlov <52973316+kozlov-alexey@users.noreply.github.com>
Co-authored-by: Vyacheslav Smirnov <vyacheslav.s.smirnov@intel.com>
densmirn added a commit that referenced this pull request May 30, 2020
* Turn on Azure CI for branch (#822)

* Redesign DataFrame structure (#817)

* Merge master (#840)

* Df.at impl (#738)

* Series.add / Series.lt with fill_value (#655)

* Impl Series.skew() (#813)

* Run tests in separate processes (#833)

* Run tests in separate processes

* Take tests list from sdc/tests/__init__.py

* change README (#818)

* change README

* change README for doc

* add refs

* change ref

* change ref

* change ref

* change readme

* Improve boxing (#832)

* Specify sdc version from channel for examples testing (#837)

* Specify sdc version from channel for examples testing

It occurs that conda resolver can take Intel SDC package
not from first channel where it is found.
Specify particular SDC version to avoid this in examples
for now.
Also print info for environment creation and package installing

* Fix incerrectly used f-string

* Fix log_info call

* Numba 0.49.0 all (#824)

* Fix run tests

Remove import of _getitem_array1d

* expectedFailure

* expectedFailure-2

* expectedFailure-3

* Conda recipe numba==0.49

* expectedFailure-4

* Refactor imports from Numba

* Unskip tests

* Fix using of numpy_support.from_dtype()

* Unskip tests

* Fix DataFrame tests with rewrite IR without Del statements

* Unskip tests

* Fix corr_overload with type inference error for none < 1

* Fix hpat_pandas_series_cov with type inference error for none < 2

* Unskip tests

* Unskip tests

* Fixed iternext_series_array with using _getitem_array1d.

_getitem_array1d is replaced with _getitem_array_single_int in Numba 0.49.

* Unskip tests

* Unskip old test

* Fix Series.at

* Unskip tests

* Add decrefs in boxing (#836)

* Adding extension type for pd.RangeIndex (#820)

* Adding extension type for pd.RangeIndex

This commit adds Numba extension types for pandas.RangeIndex class,
allowing creation of pd.RangeIndex objects and passing and returning them
to/from nopython functions.

* Applying review comments

* Fix for PR 831 (#839)

* Update pyarrow version to 0.17.0

Update recipe, code and docs.

* Disable intel channel

* Disable intel channel for testing

* Fix remarks

Co-authored-by: Vyacheslav Smirnov <vyacheslav.s.smirnov@intel.com>

* Update to Numba 0.49.1 (#838)

* Update to Numba 0.49.1

* Fix requirements.txt

* Add travis

Co-authored-by: Elena Totmenina <totmeninal@mail.ru>
Co-authored-by: Rubtsowa <36762665+Rubtsowa@users.noreply.github.com>
Co-authored-by: Sergey Pokhodenko <sergey.pokhodenko@intel.com>
Co-authored-by: Vyacheslav-Smirnov <51660067+Vyacheslav-Smirnov@users.noreply.github.com>
Co-authored-by: Alexey Kozlov <52973316+kozlov-alexey@users.noreply.github.com>
Co-authored-by: Vyacheslav Smirnov <vyacheslav.s.smirnov@intel.com>

* Re-implement df.getitem based on new structure (#845)

* Re-implement df.getitem based on new structure

* Re-implemented remaining getitem overloads, add tests

* Re-implement df.values based on new structure (#846)

* Re-implement df.pct_change based on new structure (#847)

* Re-implement df.drop based on new structure (#848)

* Re-implement df.append based on new structure (#857)

* Re-implement df.reset_index based on new structure (#849)

* Re-implement df._set_column based on new strcture (#850)

* Re-implement df.rolling methods based on new structure (#852)

* Re-implement df.index based on new structure (#853)

* Re-implement df.copy based on new structure (#854)

* Re-implement df.isna based on new structure (#856)

* Re-implement df.at/iat/loc/iloc based on new structure (#858)

* Re-implement df.head based on new structure (#855)

* Re-implement df.head based on new structure

* Simplify codegen docstring

* Re-implement df.groupby methods based on new structure (#859)

* Re-implement dataframe boxing based on new structure (#861)

* Re-implement DataFrame unboxing (#860)

* Boxing draft

Merge branch 'master' of https://github.com/IntelPython/sdc into merge_master

# Conflicts:
#	sdc/hiframes/pd_dataframe_ext.py
#	sdc/tests/test_dataframe.py

* Implement unboxing in new structure

* Improve variable names + add error handling

* Return error status

* Move getting list size to if_ok block

* Unskipped unexpected success tests

* Unskipped unexpected success tests in GroupBy

* Remove decorators

* Change to incref False

* Skip tests failed due to unimplemented df structure

* Bug in rolling

* Fix rolling (#865)

* Undecorate tests on reading CSV (#866)

* Re-implement df structure: enable rolling tests that pass (#867)

* Re-implement df structure: refactor len (#868)

* Re-implement df structure: refactor len

* Undecorated all the remaining methods

Co-authored-by: Denis <denis.smirnov@intel.com>

* Merge master to feature/dataframe_model_refactoring (#869)

* Enable CI on master

Co-authored-by: Angelina Kharchevnikova <angelina.kharchevnikova@intel.com>
Co-authored-by: Elena Totmenina <totmeninal@mail.ru>
Co-authored-by: Rubtsowa <36762665+Rubtsowa@users.noreply.github.com>
Co-authored-by: Sergey Pokhodenko <sergey.pokhodenko@intel.com>
Co-authored-by: Vyacheslav-Smirnov <51660067+Vyacheslav-Smirnov@users.noreply.github.com>
Co-authored-by: Alexey Kozlov <52973316+kozlov-alexey@users.noreply.github.com>
Co-authored-by: Vyacheslav Smirnov <vyacheslav.s.smirnov@intel.com>
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
0