warnings

Returning a copy versus a view warning when using Python pandas dataframe

Returning a copy versus a view warning when using Python pandas dataframe Question: My purpose is to transform date column from object type in dateframe df into datetime type, but suffered a lot from view and copy warning when running the program. I’ve found some useful information from link: https://stackoverflow.com/a/25254087/3849539 And tested following three solutions, …

Total answers: 2

Python: Issue Deprecation warning when importing a function

Python: Issue Deprecation warning when importing a function Question: in a file B.py I have a function hello(). The location is deprecated and I moved it to A.py. Currently I do: def hello(): from A import hello as new_hello warnings.warn( "B.hello() is deprecated. Use A.hello() instead.", DeprecationWarning ) return new_hello() but this issues the warning …

Total answers: 1

What does it mean that a card is fixed to meet FITS standard?

What does it mean that a card is fixed to meet FITS standard? Question: I am trying to use a FITS file. I have the following code: from astropy.io import fits from astropy.wcs import WCS hdul = fits.open(fitsfilename)[0] wcs = WCS(hdul.header) It gives me these warnings: WARNING: VerifyWarning: Verification reported errors: [astropy.io.fits.verify] WARNING: VerifyWarning: Card …

Total answers: 1

How to use pytest to assert NO Warning is raised

How to use pytest to assert NO Warning is raised Question: I want to ensure that no warning at all is raised in one assertion. Could not find any explicit answer in pytest documentation about warnings. I’ve tried this, thinking maybe None would mean “nothing”: def test_AttrStr_parse_warnings(): “””Check _AttrStr.parse() raises proper warnings in proper cases.””” …

Total answers: 2

Pycharm warning: must implement all abstract methods

Pycharm warning: must implement all abstract methods Question: Code class A(object): def a(self): raise NotImplementedError class B(A): def a(self): return 7 class C(B): pass Why does Pycharm complain? Problem synopsis      Class C must implement all abstract methods Asked By: MrJ || Source Answers: It’s a reported bug – you can vote for it here: https://youtrack.jetbrains.com/issue/PY-16132 …

Total answers: 4

How to suppress matplotlib warning?

How to suppress matplotlib warning? Question: I am getting an warning from matplotlib every time I import pandas: /usr/local/lib/python2.7/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter. warnings.warn(self.msg_depr % (key, alt_key)) What is the best way to suppress it? All packages are up-to-date. Conf: OSX with a brew Python 2.7.10 (default, …

Total answers: 5

mean, nanmean and warning: Mean of empty slice

mean, nanmean and warning: Mean of empty slice Question: Say I construct three numpy arrays: a = np.array([1, 2, 3]) b = np.array([np.NaN, np.NaN, 3]) c = np.array([np.NaN, np.NaN, np.NaN]) Now I find that np.mean returns nan for both b and c: >>> np.mean(a) 2.0 >>> np.mean(b) nan >>> np.mean(c) nan Since numpy 1.8 (released …

Total answers: 3

numpy division with RuntimeWarning: invalid value encountered in double_scalars

numpy division with RuntimeWarning: invalid value encountered in double_scalars Question: I wrote the following script: import numpy d = numpy.array([[1089, 1093]]) e = numpy.array([[1000, 4443]]) answer = numpy.exp(-3 * d) answer1 = numpy.exp(-3 * e) res = answer.sum()/answer1.sum() print res But I got this result and with the error occurred: nan C:UsersDesktoptest.py:16: RuntimeWarning: invalid value …

Total answers: 2

Why only one warning in a loop?

Why only one warning in a loop? Question: I want a warning raise for each problem detected in a loop, but the warning is only raised once, the first time. For example : import warnings for i in range(10): print i warnings.warn(‘this is a warning message’) I expect : 0 UserWarning: this is a warning …

Total answers: 4

Get Traceback of warnings

Get Traceback of warnings Question: In numpy we can do np.seterr(invalid=’raise’) to get a traceback for warnings raising an error instead (see this post). Is there a general way for tracing warnings? Can I make python to give a traceback, when a warning is raised? Asked By: embert || Source Answers: Run your program like …

Total answers: 6