Skip to content

TST: test_ts_plot_format_coord ValueError: Unknown format code 'f' for object of type 'str' #7664

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

Closed
yarikoptic opened this issue Jul 4, 2014 · 7 comments · Fixed by #7675
Labels
Testing pandas testing functions or related to the test suite
Milestone

Comments

@yarikoptic
Copy link
Contributor

Only with ubuntu 12.04 i386:

======================================================================
ERROR: test_ts_plot_format_coord (pandas.tseries.tests.test_plotting.TestTSPlot)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/buildd/pandas-0.14.0+git345-g8cd3dd6/debian/tmp/usr/lib/python2.7/dist-packages/pandas/tseries/tests/test_plotting.py", line 138, in test_ts_plot_format_coord
    check_format_of_first_point(annual.plot(), 't = 2014  y = 1.000000')
  File "/tmp/buildd/pandas-0.14.0+git345-g8cd3dd6/debian/tmp/usr/lib/python2.7/dist-packages/pandas/tseries/tests/test_plotting.py", line 135, in check_format_of_first_point
    self.assertEqual(expected_string, ax.format_coord(first_x, first_y))
  File "/tmp/buildd/pandas-0.14.0+git345-g8cd3dd6/debian/tmp/usr/lib/python2.7/dist-packages/pandas/tseries/plotting.py", line 90, in <lambda>
    y))
ValueError: Unknown format code 'f' for object of type 'str'
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.3.final.0
python-bits: 32
OS: Linux
OS-release: 3.2.0-4-amd64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: C
LANG: C

pandas: 0.14.0.dev
nose: 1.1.2
Cython: 0.15.1
numpy: 1.6.1
scipy: 0.9.0
statsmodels: 0.5.0
IPython: None
sphinx: 1.1.3
patsy: 0.2.1
scikits.timeseries: None
dateutil: 1.5
pytz: 2012c
bottleneck: None
tables: 2.3.1
numexpr: 1.4.2
matplotlib: 1.1.1rc
openpyxl: 1.7.0
xlrd: 0.6.1
xlwt: 0.7.2
xlsxwriter: None
lxml: None
bs4: 4.0.2
html5lib: 0.90
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: None
@jreback jreback added the Testing label Jul 4, 2014
@jreback jreback added this to the 0.14.1 milestone Jul 4, 2014
@jreback
Copy link
Contributor

jreback commented Jul 5, 2014

cc @sinhrks and thoughts in this?

@sinhrks
Copy link
Member

sinhrks commented Jul 6, 2014

Not sure, but maybe dtype is changed in either process? Whichever, it may better to add error handling process in format_coord.

  • Series construction using single value (may result in object dtype?)
  • Or matplotlib internal process?

@yarikoptic Can you attach the result of the following code to confirm when dtype is changed?

import pandas as pd

print('instanciate with value')
annual = pd.Series(1, index=pd.date_range('2014-01-01', periods=3, freq='A-DEC'))
print('dtype', annual.dtypes, annual.values)
ax = annual.plot()
first_line = ax.get_lines()[0]
first_y = first_line.get_ydata()[0]
print('first_y', type(first_y), first_y)
first_y = first_line.get_ydata(orig=True)[0]
print('first_y_orig', type(first_y), first_y)
first_y = first_line.get_ydata(orig=False)[0]
print('first_y_conv', type(first_y), first_y)

print('instanciate with list')
annual = pd.Series([1, 1, 1], index=pd.date_range('2014-01-01', periods=3, freq='A-DEC'))
print('dtype', annual.dtypes, annual.values)
ax = annual.plot()
first_line = ax.get_lines()[0]
first_y = first_line.get_ydata()[0]
print('first_y', type(first_y), first_y)
first_y = first_line.get_ydata(orig=True)[0]
print('first_y_orig', type(first_y), first_y)
first_y = first_line.get_ydata(orig=False)[0]
print('first_y_conv', type(first_y), first_y)

@yarikoptic
Copy link
Contributor Author

here you go sir

# PYTHONPATH=/tmp/buildd/pandas-0.14.0+git345-g8cd3dd6/debian/tmp/usr/lib/python2.7/dist-packages/ xvfb-run -a -s "-screen 0 1280x1024x24 -noreset" python /tmp/testcode.py 
instanciate with value
('dtype', dtype('int64'), array([1, 1, 1], dtype=int64))
('first_y', <type 'numpy.int64'>, 1)
('first_y_orig', <type 'numpy.int64'>, 1)
instanciate with list
('dtype', dtype('int64'), array([1, 1, 1], dtype=int64))
('first_y', <type 'numpy.int64'>, 1)
('first_y_orig', <type 'numpy.int64'>, 1)

@yarikoptic
Copy link
Contributor Author

most probably it was not a type change but rather some incorrect type checking inside somewhere, and probably elderly numpy to blame (since doesn't appear with newer releases I guess was fixed)?

(Pdb) print "t = {0}  y = {1:8f}".format(Period(ordinal=int(t), freq=ax.freq),y)
*** ValueError: Unknown format code 'f' for object of type 'str'
(Pdb) print y
1
(Pdb) print type(y)
<type 'numpy.int64'>
(Pdb) print np.__version__
1.6.1

@jreback
Copy link
Contributor

jreback commented Jul 6, 2014

@yarikoptic this works for me on 1.6.1, but using matplotlib 1.1.1 (I don't have 1.1.1rc). Can you update and try with that?

@jreback
Copy link
Contributor

jreback commented Jul 7, 2014

I can just skip this on old numpy too?

@yarikoptic
Copy link
Contributor Author

and 32bit? I guess you could indeed just skip it or (to just help yourself if users on those start chasing you) wrap into try/except and then may be spit out warning and use '%s' for that one in those cases or smth like that?

(Pdb) print "t = {0}  y = {1:8s}".format(Period(ordinal=int(t), freq=ax.freq),y)
t = 2014  y = 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants