Repository: piskvorky/gensim

Issue:
DeprecationWarning: inspect.getargspec() is deprecated in phrases.py:317
<!--
If your issue is a usage or a general question, please submit it here instead:
- Mailing List: https://groups.google.com/forum/#!forum/gensim
For more information, see Recipes&FAQ: https://github.com/RaRe-Technologies/gensim/wiki/Recipes-&-FAQ
-->

<!-- Instructions For Filing a Bug: https://github.com/RaRe-Technologies/gensim/blob/develop/CONTRIBUTING.md -->

#### Description
I wanted to add bigrams/trigrams by using `Phrases()` but something went wrong
#### Steps/Code/Corpus to Reproduce

``` python
from gensim.models import Phrases 
#1st way to get error
bigram_model = Phrases()

#2nd way to get error
bigram_model = Phrases(['aaa', 'aaa'])
```

#### Expected Results
Two get bigrams. I have got them, but I have confused by the errors/warnings below
#### Actual Results
```
C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\phrases.py:317: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
  if all(parameter in getargspec(scoring)[0] for parameter in scoring_parameters):
C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\phrases.py:317: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
  if all(parameter in getargspec(scoring)[0] for parameter in scoring_parameters):
C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\phrases.py:317: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
  if all(parameter in getargspec(scoring)[0] for parameter in scoring_parameters):
C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\phrases.py:317: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
  if all(parameter in getargspec(scoring)[0] for parameter in scoring_parameters):
C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\phrases.py:317: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
  if all(parameter in getargspec(scoring)[0] for parameter in scoring_parameters):
C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\gensim\models\phrases.py:317: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() or inspect.getfullargspec()
  if all(parameter in getargspec(scoring)[0] for parameter in scoring_parameters):
```
Please paste or specifically describe the actual output or traceback. -->

#### Versions
```
Windows-10-10.0.15063-SP0
Python 3.6.3 |Anaconda, Inc.| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)]
NumPy 1.14.0
SciPy 0.19.1
gensim 3.3.0
FAST_VERSION 1
```


<!-- Thanks for contributing! -->




Discussion:
Hello @Diyago, thanks for the report, this is an only warning, not an error, the model works fine.
Anyway, we should replace `getargspec` because this is deprecated.
@menshikh-iv what is the expected behavior in python 2.7? I think we  should still use `getargspec()` 

correct me if I'm wrong
@naveenkumarmarri for 2.7 `getargspec` is fine, this deprecated since `python 3.0` (https://docs.python.org/3/library/inspect.html#inspect.getargspec). We still use `getagrspec` for `py2`, but for `py3` need to fix this problem.
@menshikh-iv 
I am trying to reproduce the error on a windows 10 with python 3.6.3

This is what I get:

```
(gensim_env) (base) D:\Projects\gensim>python test_script.py
D:\Projects\gensim\gensim\utils.py:1167: UserWarning: detected Windows; aliasing chunkize to chunkize_serial
  warnings.warn("detected Windows; aliasing chunkize to chunkize_serial")
Phrases<2 vocab, min_count=5, threshold=10.0, max_vocab_size=40000000>

(gensim_env) (base) D:\Projects\gensim>python --version
Python 3.6.3 :: Anaconda, Inc.
```


The chunkize part is fine. The file I'm running has the code provided by @Diyago 
@aneesh-joshi try to force warnings: `python -Wd test_script.py` 
@menshikh-iv 
I managed to remove the warning by replacing `getargspec` with `getfullargspec` as suggested in https://docs.python.org/3/library/inspect.html#inspect.getargspec

However, it is only for python 3 and won't work for python 2.

Is there any way to use different functions depending on the python version.


Moreover, forcing warnings brings out some other deprecation warnings
```
(gensim_env) (base) D:\Projects\gensim>python -Wd test_script.py
D:\Projects\gensim\gensim_env\lib\site.py:165: DeprecationWarning: 'U' mode is deprecated
  f = open(fullname, "rU")
D:\Projects\gensim\gensim_env\lib\site-packages\boto\plugin.py:40: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
D:\Projects\gensim\gensim\utils.py:1167: UserWarning: detected Windows; aliasing chunkize to chunkize_serial
  warnings.warn("detected Windows; aliasing chunkize to chunkize_serial")
D:\Projects\gensim\gensim_env\lib\importlib\_bootstrap.py:219: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  return f(*args, **kwds)
D:\Projects\gensim\gensim_env\lib\site-packages\scipy\sparse\sparsetools.py:20: DeprecationWarning: 
scipy.sparse.sparsetools` is deprecated!
scipy.sparse.sparsetools is a private module for scipy.sparse, and should not be used.
  _deprecated()
```

Should I do anything about this?
@aneesh-joshi yes, you can fix this if you use needed function (depends on python version) or probably `six` (I'm not sure about it).

About `sparsetools`, you can't do anything right now, we want to make our own "spasetools subset" package as [GSoC task](https://github.com/RaRe-Technologies/gensim/wiki/GSoC-2018-project-ideas#sparsetools-package).
@menshikh-iv 
Please review the [PR](https://github.com/RaRe-Technologies/gensim/pull/1885/files)

Resolving patch:
diff --git a/gensim/models/phrases.py b/gensim/models/phrases.py
--- a/gensim/models/phrases.py
+++ b/gensim/models/phrases.py
@@ -83,14 +83,18 @@
 import functools as ft
 import itertools as it
 from math import log
-from inspect import getargspec
 import pickle
 import six
 
-from six import iteritems, string_types, next
+from six import iteritems, string_types, PY2, next
 
 from gensim import utils, interfaces
 
+if PY2:
+    from inspect import getargspec
+else:
+    from inspect import getfullargspec as getargspec
+
 logger = logging.getLogger(__name__)
 
 


Test patch: