pandas-dev / pandas

Flexible and powerful data analysis / manipulation library for Python, providing labeled data structures similar to R data.frame objects, statistical functions, and much more
https://pandas.pydata.org
BSD 3-Clause "New" or "Revised" License
43.79k stars 17.97k forks source link

python3.2 offsets.py: TypeError: Cannot cast ufunc subtract input from dtype('<M8[D]') to dtype('<M8[us]') with casting rule 'same_kind' #4263

Closed yarikoptic closed 11 years ago

yarikoptic commented 11 years ago

in pandas.tseries.tests.test_daterange.TestCustomDateRange tests many fail at v0.12.0rc1-90-g4c2d050

======================================================================
ERROR: test_repr (pandas.tseries.tests.test_daterange.TestCustomDateRange)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/tests/test_daterange.py", line 383, in setUp
    self.rng = cdate_range(START, END)
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/index.py", line 1791, in cdate_range
    tz=tz, normalize=normalize, name=name, **kwargs)
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/index.py", line 180, in __new__
    tz=tz, normalize=normalize)
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/index.py", line 373, in _generate
    index = _generate_regular_range(start, end, periods, offset)
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/index.py", line 1663, in _generate_regular_range
    dates = list(xdr)
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/offsets.py", line 1363, in generate_range
    next_date = offset.apply(cur)
  File "/home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/offsets.py", line 453, in apply
    time = dt64 - day64
TypeError: Cannot cast ufunc subtract input from dtype('<M8[D]') to dtype('<M8[us]') with casting rule 'same_kind'

system info

INSTALLED VERSIONS
------------------
Python: 3.2.4.final.0
OS: Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2 x86_64
LC_ALL: None
LANG: en_US

Cython: 0.19
Numpy: 1.8.0.dev-Unknown
Scipy: 0.10.1
statsmodels: Not installed
    patsy: Not installed
scikits.timeseries: Not installed
dateutil: 2.0
pytz: 2012c
bottleneck: Not installed
PyTables: Not Installed
    numexpr: 2.1
matplotlib: Not installed
openpyxl: Not installed
xlrd: Not installed
xlwt: Not installed
sqlalchemy: Not installed
lxml: 3.2.0
bs4: 4.2.1
html5lib: Not installed
jreback commented 11 years ago

passes fine with numpy 1.7.1....can you print out these dt64 and day64 (and their dtypes)?

what arch is this on?

jreback commented 11 years ago

sorry..you already posted the OS!

jreback commented 11 years ago

@cpcloud how do I build numpy on 3? the usual python3 setup.py build doesn't seem to work?

cpcloud commented 11 years ago

r u in a virtualenv?

cpcloud commented 11 years ago

can u pip install numpy it? any reason not to do that?

jreback commented 11 years ago

this is not a virtuenv....sort of an older install....I have a cloned numpy....but weird that no instructions to build py3

cpcloud commented 11 years ago

let me see if i can do it on my box...it's been a while since i haven't used virtualenv

cpcloud commented 11 years ago

builds ok for me outside of venv with python3.3 setup.py build

cpcloud commented 11 years ago

stupid question: did u give the minor version? python3.2 works for me as well.

cpcloud commented 11 years ago

@jreback where does the build fail for you?

yarikoptic commented 11 years ago

if you have a debian-based system you can easily debootstrap a similiar sid environment. Let me know if you need a 1 liner

test_cached_range (pandas.tseries.tests.test_daterange.TestCustomDateRange) ... > /home/yoh/deb/gits/pkg-exppsy/build-area/pandas-0.12.0~rc1+git90-g4c2d050/debian/tmp/usr/lib/python3/dist-packages/pandas/tseries/offsets.py(453)apply()
-> time = dt64 - day64
(Pdb) print dt64
numpy.datetime64('2008-12-31T19:00:00.000000-0500')
(Pdb) print day64
numpy.datetime64('2009-01-01')
(Pdb) dt64 - day64
*** TypeError: Cannot cast ufunc subtract input from dtype('<M8[D]') to dtype('<M8[us]') with casting rule 'same_kind'
jreback commented 11 years ago

I recloned and it built fine...(I had py2.7 inplace, maybe that doesn't work with numpy for some reason)

yarikoptic commented 11 years ago

@cpcloud -- whenever there is more than 1 soul in the discussion, please direct your questions with @nickname, otherwise hard to deduce whom you ask.

Cheers

cpcloud commented 11 years ago

@yarikoptic no problem! sorry bout that

jreback commented 11 years ago

@yarikoptic

do you get an error doing this? (works fine on 1.7.1 as well)

In [1]: x  = numpy.datetime64('2008-12-31T19:00:00.000000-0500')

In [2]: x-numpy.datetime64('2009-01-01')
Out[2]: numpy.timedelta64(0,'us')

In [3]: np.__version__
Out[3]: '1.8.0.dev-b55f275'

In [4]: import sys

In [5]: sys.version
Out[5]: '3.3.0 (default, Feb  1 2013, 08:25:35) \n[GCC 4.4.5]'
yarikoptic commented 11 years ago
(Pdb) x  = np.datetime64('2008-12-31T19:00:00.000000-0500')
(Pdb) x-np.datetime64('2009-01-01')
*** TypeError: Cannot cast ufunc subtract input from dtype('<M8[D]') to dtype('<M8[us]') with casting rule 'same_kind'
(Pdb) np.__version__
'1.8.0.dev-Unknown'
(Pdb) import sys
(Pdb) sys.version
'3.2.4 (default, May  8 2013, 20:55:18) \n[GCC 4.7.3]'
jreback commented 11 years ago

that is really odd..

how old 1.8 are you running? (I ran with master)

yarikoptic commented 11 years ago

Mine is actually 1.7.1 release according to the Debian package version... not sure why python3 build reports it as 1.8.0.dev while python one correctly as 1.7.1

jreback commented 11 years ago

so the only different between what you are running and below is python 3.2.4 vs 3.2.3? if so that is REALLY weird

Python 3.2.3 (default, Jun  5 2013, 15:13:28) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'1.7.1'
>>> x  = np.datetime64('2008-12-31T19:00:00.000000-0500')
>>> x-numpy.datetime64('2009-01-01')
>>> x-np.datetime64('2009-01-01')
numpy.timedelta64(0,'us')
yarikoptic commented 11 years ago

grrr.... that 1.8.0.dev it was not 1.7.1 -- I had some stale /local installation (not sure how it got there) which was picked up (just removed it now).

I will try to rebuild now with stock 1.7.1 all around

On Tue, 16 Jul 2013, jreback wrote:

that is really odd..

how old 1.8 are you running? (I ran with master)

— Reply to this email directly or [1]view it on GitHub.

References

Visible links

  1. https://github.com/pydata/pandas/issues/4263#issuecomment-21066594

Yaroslav O. Halchenko, Ph.D. http://neuro.debian.net http://www.pymvpa.org http://www.fail2ban.org Senior Research Associate, Psychological and Brain Sciences Dept. Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755 Phone: +1 (603) 646-9834 Fax: +1 (603) 646-1419 WWW: http://www.linkedin.com/in/yarik

jreback commented 11 years ago

@yarikoptic great...let us know!

jreback commented 11 years ago

@yarikoptic resolved?

yarikoptic commented 11 years ago

seems to me

$> grep -e nosetests -e test_repr.*pandas.tseries.tests.test_daterange.TestCustomDateRang pandas_0.12.0~rc1+git101-gd070a1f-1_amd64.build 
    cd build/; python2.7 /usr/bin/nosetests -s -v -a '!network'  pandas;
test_repr (pandas.tseries.tests.test_daterange.TestCustomDateRange) ... ok
    cd build/; python3.2 /usr/bin/nosetests -s -v -a '!network'  pandas;
test_repr (pandas.tseries.tests.test_daterange.TestCustomDateRange) ... ok