Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csort range py3 compatible #32

Conversation

earthgecko
Copy link
Contributor

In tests/fixtures.py csort does not work on 3.5 as range has changed type from
list to class in py3 - fixed and tested ok on 2.7 and 3.5

Implications of the type change of range from list to class in py3 could have
some deeper ramifications - https://github.com/blue-yonder/tsfresh/search?p=2&q=range

debug info

tests/test_relevant_feature_extraction.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <tests.test_relevant_feature_extraction.RelevantFeatureExtractionTestCase testMethod=test_functional_equality>

    def create_test_data_sample_with_target(self):
        """
            Small test data set with target.
            :return: timeseries df
            :return: target y which is the mean of each sample's timeseries
            """
        cid = np.repeat(range(50), 3)
>       csort = range(3) * 50
E       TypeError: unsupported operand type(s) for *: 'range' and 'int'

tests/fixtures.py:44: TypeError
=============================================================================================================== 1 failed in 2.56 seconds ================================================================================================================
(tsfresh-py352) gary@mc11:/opt/python_virtualenv/projects/tsfresh-py352/apps/tsfresh$
(tsfresh-py352) gary@mc11:/opt/python_virtualenv/projects/tsfresh-py352/apps/tsfresh$ python
Python 3.5.2 (default, Jul 11 2016, 13:20:59)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> csort = range(3) * 50
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'range' and 'int'
>>>
TypeError: unsupported operand type(s) for *: 'range' and 'int'
>>> range(3)
range(0, 3)
>>>

Fine on 2.7.12 as different implementation

(tsfresh-py2712) gary@mc11:/opt/python_virtualenv/projects/tsfresh-py2712/apps/tsfresh_master$ python
Python 2.7.12 (default, Aug 20 2016, 09:15:25)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> csort = range(3) * 50
>>> print(csort)
[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
>>> range(3)
[0, 1, 2]
>>>

solve

Pattern that provides the same results on 2.7 and 3.5

(tsfresh-py352) gary@mc11:/opt/python_virtualenv/projects/tsfresh-py352/apps/tsfresh$ python
Python 3.5.2 (default, Jul 11 2016, 13:20:59)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> list(range(3))
[0, 1, 2]
>>> list(range(3)) * 50
[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
>>>
(tsfresh-py2712) gary@mc11:/opt/python_virtualenv/projects/tsfresh-py2712/apps/tsfresh$ python
Python 2.7.12 (default, Aug 20 2016, 09:15:25)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> list(range(3))
[0, 1, 2]
>>> list(range(3)) * 50
[0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]
>>>

Changed and tests/test_relevant_feature_extraction.py works and passes on both
2.7.12 and 3.5.2.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 94.85% when pulling 5d03264 on earthgecko:i8_add_python3_support_earthgecko into 47c1ff0 on blue-yonder:i8_add_python3_support.

Due to a change in unittest in as identified by @jneuff in
blue-yonder#8 (comment)

Semantically they appear to be the same and this fixes the related failing
tests on Python 3.5 as described in the gist in
blue-yonder#8 (comment)

Adds a basic method to determine python version for now, only committing so that
the new deeper unitest.assertEqual issue that now presents itself can be
addressed.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 94.85% when pulling 7c2be54 on earthgecko:i8_add_python3_support_earthgecko into 47c1ff0 on blue-yonder:i8_add_python3_support.

@MaxBenChrist
Copy link
Collaborator

Great work @earthgecko . I will rewrite the unit tests using the six package

import six
import unittest
class TestAssertCountEqual(unittest.TestCase): def test(self):
        six.assertCountEqual(self, (1, 2), [2, 1])

@MaxBenChrist MaxBenChrist merged commit 89590c0 into blue-yonder:i8_add_python3_support Nov 3, 2016
MaxBenChrist added a commit that referenced this pull request Nov 4, 2016
* use python3 compatible print function

* use absolute import for py3 support

* in py3 one has to load reduce

* check for basestring in column name

* import range for py3 support

* call list of range iterator

* fixed standard library import

* added builtin support for str, basestring, zip, object

* class FeatureExtractionSettings inherits from baseobject

* call list of iterator objects

* change iter() to iteritems()

* replaced filter by list comprehension

* added future to requirements.txt

* Changed xrange to range for #8 (#30)

* csort range py3 compatible (#32)

* Changed xrange to range for #8

* Modified csort due to range changing from list to type for #8

* Use assertItemsEqual py2 and assertCountEqual py3
Due to a change in unittest in as identified by @jneuff in
#8 (comment)

Semantically they appear to be the same and this fixes the related failing
tests on Python 3.5 as described in the gist in
#8 (comment)

Adds a basic method to determine python version for now, only committing so that
the new deeper unitest.assertEqual issue that now presents itself can be
addressed.

* pinned version of future package

* added six to test-requirements.txt

* use six for assertCountEqual unit testing

* deleted some comments

* use six for assertCountEqual to test feature_augmentor

__dict__ will give iterator for properties

* use six.assertCountEqual

* use assertGreaterEqual to test subset

* parameter have to be sorted in feature name

fixes bug #29, features with multiple, but same parameters could end up
with different names

* added python 3.5.2 to .travis.yml

closes #8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants