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

deprecation prep #1399

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft

deprecation prep #1399

wants to merge 9 commits into from

Conversation

jamesmkrieger
Copy link
Contributor

I have introduced some try/except blocks to account for things becoming deprecated. The relevant warnings came from pytest from Python 3.8 on Ubuntu 20.04 (Windows Subsystem for Linux 2):

prody/atomic/select.py:445
  /mnt/c/Users/james/code/ProDy/prody/atomic/select.py:445: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
    from collections import Iterable

prody/apps/evol_apps/__init__.py:3
  /mnt/c/Users/james/code/ProDy/prody/apps/evol_apps/__init__.py:3: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

prody/compounds/pdbligands.py:161
prody/compounds/pdbligands.py:161
  /mnt/c/Users/james/code/ProDy/prody/compounds/pdbligands.py:161: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    leaving_atom_flags = np.zeros(n_atoms, np.bool)

prody/compounds/pdbligands.py:162
prody/compounds/pdbligands.py:162
  /mnt/c/Users/james/code/ProDy/prody/compounds/pdbligands.py:162: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    aromatic_flags = np.zeros(n_atoms, np.bool)

prody/compounds/pdbligands.py:163
prody/compounds/pdbligands.py:163
  /mnt/c/Users/james/code/ProDy/prody/compounds/pdbligands.py:163: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    stereo_configs = np.zeros(n_atoms, np.bool)

prody/trajectory/dcdfile.py:273: 2 warnings
prody/tests/apps/test_prody_catdcd.py: 38 warnings
prody/tests/apps/test_prody_pca.py: 4 warnings
prody/tests/measure/test_measure.py: 10 warnings
prody/tests/trajectory/test_dcdfile.py: 4 warnings
prody/tests/trajectory/test_frame.py: 6 warnings
  /mnt/c/Users/james/code/ProDy/prody/trajectory/dcdfile.py:273: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
    xyz = fromstring(self._file.read(self._itemsize * n_floats),

prody/trajectory/dcdfile.py:320: 1 warning
prody/tests/apps/test_prody_catdcd.py: 6 warnings
prody/tests/measure/test_measure.py: 2 warnings
prody/tests/trajectory/test_dcdfile.py: 3 warnings
  /mnt/c/Users/james/code/ProDy/prody/trajectory/dcdfile.py:320: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
    data = fromstring(data, self._dtype)

prody/sequence/sequence.py:32: 75 warnings
prody/tests/sequence/test_msafile.py: 175 warnings
  /mnt/c/Users/james/code/ProDy/prody/sequence/sequence.py:32: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
    self._seq = fromstring(one, '|S1')

prody/tests/apps/test_prody_catdcd.py: 21 warnings
prody/tests/measure/test_measure.py: 6 warnings
prody/tests/trajectory/test_frame.py: 6 warnings
  /mnt/c/Users/james/code/ProDy/prody/trajectory/dcdfile.py:294: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
    unitcell = fromstring(self._file.read(48), dtype=np.float64)

prody/tests/ensemble/test_functions.py: 9 warnings
prody/tests/ensemble/test_pdbensemble.py: 19 warnings
prody/tests/sequence/test_msa.py: 25 warnings
prody/tests/sequence/test_msafile.py: 100 warnings
prody/tests/sequence/test_sequence.py: 1 warning
  /mnt/c/Users/james/code/ProDy/prody/sequence/sequence.py:52: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
    return self._array.tostring().decode()

prody/tests/sequence/test_analysis.py: 129 warnings
  /mnt/c/Users/james/code/ProDy/prody/sequence/analysis.py:592: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    c = matrix.dot(matrix(zeros((length*q, 1), float)),

prody/tests/sequence/test_analysis.py: 129 warnings
  /mnt/c/Users/james/code/ProDy/prody/sequence/analysis.py:593: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    matrix(zeros((1, length*q), float)))

prody/tests/sequence/test_analysis.py: 129 warnings
  /home/jkrieger/anaconda3/envs/wsl_prody/lib/python3.8/site-packages/numpy/matrixlib/defmatrix.py:69: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray.
    return matrix(data, dtype=dtype, copy=False)

prody/tests/sequence/test_sequence.py::TestSequence::testStringConversion
  /mnt/c/Users/james/code/ProDy/prody/sequence/sequence.py:36: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
    self._seq = fromstring(args[0], '|S1')

-- Docs: https://docs.pytest.org/en/stable/warnings.html

I have accounted for a number of these but not all of them.

@jamesmkrieger
Copy link
Contributor Author

jamesmkrieger commented Aug 1, 2021

I haven't quite worked out how to automatically trigger GitHub Actions CI, but here's the output from manually triggering on this branch: https://github.com/jamesmkrieger/ProDy/actions/runs/1087735002

This check passed.

try:
heatmap.append(fromstring(items[-1], float, sep=';'))
except:
heatmap.append(frombuffer(items[-1], float, sep=';'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

These fixes might be too ad-hoc. There should be a better way to determine which function to use. In addition, it is better the catch the specific error than a general "except"

self._labels[rows])
except:
return Sequence(self._msa[rows, cols].tobytes(),
self._labels[rows])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same issue with these lines. Maybe use PY3K macro to check this?

Copy link
Contributor Author

@jamesmkrieger jamesmkrieger Oct 25, 2021

Choose a reason for hiding this comment

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

We have the following block in the Sequence object, on which we could maybe base these:

        if PY3K:
            try:
                return self._array.tostring().decode()
            except:
                return self._array.tobytes().decode()
        else:
            return self._array.tostring()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've now tried this

scripts/evol Outdated Show resolved Hide resolved
scripts/prody Outdated Show resolved Hide resolved
@jamesmkrieger jamesmkrieger marked this pull request as draft December 20, 2021 17:54
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.

2 participants