Skip to content

Changes intended to assist with investigation of issue #28 (possibly also issue #23) - #29

Closed
tim-littlefair wants to merge 3 commits into
exhuma:masterfrom
tim-littlefair:master
Closed

tim-littlefair wants to merge 3 commits into
exhuma:masterfrom
tim-littlefair:master

Conversation

@tim-littlefair

@tim-littlefair tim-littlefair commented Mar 9, 2018 •

Copy link
Copy Markdown
Contributor

I have added an extra test class to hierarchical_test.py which includes a set of data which illustrates the difference in behaviour between Python2.7 and Python3.5 which caused me to raise this issue.

From analysis of log files, I believe the point at which the behaviour of this test under the two Python versions begins to diverge in the python-cluster 1.4.1 code is the following four lines in matrix.py:

                    if not hasattr(item, '__iter__') or isinstance(item, tuple):
                        item = [item]
                    if not hasattr(item2, '__iter__') or isinstance(item2, tuple):
                        item2 = [item2]

I've replaced these four lines with a single function, invoked twice, which logs the name of type of the original item and the name of the type it is converted two. From these log messages, I'm fairly certain that the problem is caused by the fact that Python2.7 (which works) encapsulates any item which is of type str as a list containing that str, whereas Python3.5 (which does not work) passes the str object on unchanged, with the result that later logic unpacks the string one character at a time instead of handling it as a whole.

I think the change in behaviour here may also be related to issue #23 (based on exhuma's comment on that issue dated 15 May 2017.

I will continue to investigate this issue when I get time and will cancel this PR and issue a new one if I feel I have a robust fix.

…ws an exception under Python3.5 (both on macOS).

As well as adding the test class, this commit turns on DEBUG level logging, which makes it easier to spot the point at which
the behaviour of the two versions diverge.
… to the logic linkage.py.

This change ensures that the tests which have been written in this file can be run from the CLI.
The tests presently run successfully under both Python2.7 and Python3.5.
…on call, which is intended to be identical in effect, but provides an informative log message.

With this commit, the behaviour of the test_hierarchical.py test set remains identical to python-cluster 1.4.1 under both Python2.7 (which passes)_and Python3.5 (which fails with a KeyError thrown).
@tim-littlefair tim-littlefair changed the title Changes intended to assist with investigation of issue #28 (possibly also issue #22) Changes intended to assist with investigation of issue #28 (possibly also issue #23) Mar 9, 2018
@tim-littlefair

Copy link
Copy Markdown
Contributor Author

I am cancelling this pull request as I intend to submit a better one, which I believe resolves issue #28 (at least in relation to the specific problem I am having, where the list of items to be clustered contains keys of type str).

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.

1 participant