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

Warnings when spacy called from unittest #1706

Closed
joelb-git opened this issue Dec 10, 2017 · 4 comments
Closed

Warnings when spacy called from unittest #1706

joelb-git opened this issue Dec 10, 2017 · 4 comments
Labels
enhancement Feature requests and improvements help wanted (easy) Contributions welcome! (also suited for spaCy beginners) help wanted Contributions welcome!

Comments

@joelb-git
Copy link

I see warnings when spacy is called from unittest. I do not see these warning from
non-unittest contexts.

$ cat testcase.py
import unittest
import spacy

class SpacyTestCase(unittest.TestCase):
    def test_spacy(self):
        nlp = spacy.load('en')
        doc = nlp('this is just a test.')
        print(doc)

$ python -m unittest testcase.py
/Users/joelb/venv3/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)
/Users/joelb/venv3/lib/python3.6/importlib/_bootstrap.py:205: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192, got 176
  return f(*args, **kwds)
/Users/joelb/venv3/lib/python3.6/importlib/_bootstrap.py:205: ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
  return f(*args, **kwds)
/Users/joelb/venv3/lib/python3.6/site-packages/spacy/util.py:521: ResourceWarning: unclosed file <_io.BufferedReader name='/Users/joelb/venv3/lib/python3.6/site-packages/spacy/data/en/en_core_web_sm-2.0.0/vocab/key2row'>
  reader(path / key)
/Users/joelb/venv3/lib/python3.6/site-packages/spacy/language.py:618: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/joelb/venv3/lib/python3.6/site-packages/spacy/data/en/en_core_web_sm-2.0.0/meta.json' mode='r' encoding='UTF-8'>
  ('meta.json', lambda p: self.meta.update(ujson.load(p.open('r'))))
/Users/joelb/venv3/lib/python3.6/site-packages/spacy/util.py:521: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/joelb/venv3/lib/python3.6/site-packages/spacy/data/en/en_core_web_sm-2.0.0/tagger/cfg' mode='r' encoding='UTF-8'>
  reader(path / key)
/Users/joelb/venv3/lib/python3.6/site-packages/spacy/util.py:521: ResourceWarning: unclosed file <_io.BufferedReader name='/Users/joelb/venv3/lib/python3.6/site-packages/spacy/data/en/en_core_web_sm-2.0.0/tagger/model'>
  reader(path / key)
/Users/joelb/venv3/lib/python3.6/site-packages/spacy/util.py:521: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/joelb/venv3/lib/python3.6/site-packages/spacy/data/en/en_core_web_sm-2.0.0/parser/cfg' mode='r' encoding='UTF-8'>
  reader(path / key)
/Users/joelb/venv3/lib/python3.6/site-packages/spacy/util.py:521: ResourceWarning: unclosed file <_io.TextIOWrapper name='/Users/joelb/venv3/lib/python3.6/site-packages/spacy/data/en/en_core_web_sm-2.0.0/ner/cfg' mode='r' encoding='UTF-8'>
  reader(path / key)
this is just a test.
.
----------------------------------------------------------------------
Ran 1 test in 2.013s

OK

To suppress the warnings:

$ python  -W ignore:ResourceWarning -m unittest testcase.py
this is just a test.
.
----------------------------------------------------------------------
Ran 1 test in 1.933s

OK

however since these did not appear until after we upgraded to spaCy 2.x,
I thought it was worth reporting.

Your Environment

$ python -m spacy info --markdown

Info about spaCy

  • spaCy version: 2.0.5
  • Platform: Darwin-16.7.0-x86_64-i386-64bit
  • Python version: 3.6.0
  • Models: en
@ines
Copy link
Member

ines commented Dec 10, 2017

Thanks! 👍 We should probably replace the loading of the meta.json with a helper function that closes the file properly:

('meta.json', lambda p: self.meta.update(ujson.load(p.open('r'))))

I think we even have a spacy.util.read_json that does exactly that – it just needs to be tested to make sure it works as expected and has no weird side-effects (since the code is part of an ordered dicts of deserializers).

@ines ines added enhancement Feature requests and improvements help wanted Contributions welcome! help wanted (easy) Contributions welcome! (also suited for spaCy beginners) labels Dec 10, 2017
@uwaisiqbal
Copy link

Can I take this on? I'm a new contributor and would like to get my first PR.

@ines
Copy link
Member

ines commented Feb 8, 2018

@Oasis789 So sorry about the late reply – I totally missed your comment. If you still want to take this on, that would be great, thanks! 👍

@ursachec ursachec mentioned this issue Feb 13, 2018
3 tasks
honnibal added a commit that referenced this issue Feb 15, 2018
@lock
Copy link

lock bot commented May 7, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Feature requests and improvements help wanted (easy) Contributions welcome! (also suited for spaCy beginners) help wanted Contributions welcome!
Projects
None yet
Development

No branches or pull requests

4 participants