On 05/06/2018 01:00, Andreas Tille wrote:

> ======================================================================
> ERROR: test_consistent_gap_degen_handling 
> (test_core.test_sequence.ModelSequenceTests)
> gap degen character should be treated consistently
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File 
> "/tmp/autopkgtest-lxc.5a99fnj6/downtmp/autopkgtest_tmp/tests/test_core/test_sequence.py",
>  line 660, in test_consistent_gap_degen_handling
>     self.assertEqual(dna.stripBadAndGaps(), raw_ungapped)
>   File "/usr/lib/python2.7/dist-packages/cogent/core/sequence.py", line 1251, 
> in stripBadAndGaps
>     valid_indices -= self._data == i
> TypeError: numpy boolean subtract, the `-` operator, is deprecated, use the 
> bitwise_xor, the `^` operator, or the logical_xor function instead.
> 
> ======================================================================
> 
> 
> I would be happy for some suggested patch how to solve this.  The line
> in question is
> 
>    
> https://salsa.debian.org/med-team/python-cogent/blob/master/cogent/core/sequence.py
> 
>    Line 1251
> 
> If my feeling is not totally wrong the correct patch would be 
> 
>    valid_indices -= (self._data == i)
> 
> since the left value is rather an integer than boolean.
> 
> What do you think?

Without analyzing the code in the fine details, and assuming self._data
is a numpy array or a subclass, I think the name of the variable is
misleading.  Looking at the whole function it seems to be a bool array.
It should be easy to confirm this with pdb or simply inserting a print()
statement in the right place.

    def stripBadAndGaps(self):
        """Returns copy of self with bad chars and gaps excised."""
        gap_indices = map(self.Alphabet.index, self.MolType.Gaps)
        valid_indices = self._data < len(self.Alphabet)
        for i in gap_indices:
            valid_indices -= self._data == i
        result = compress(valid_indices, self._data)
        return self.__class__(result, Info=self.Info)

The fix should be to replace the subtraction with:

    valid_indices ^= self._data == i

Cheers,
Dan

Reply via email to