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

BUG: datetimelike subtract incorrect when broadcasting #12437

Closed
Tracked by #18824
toobaz opened this issue Feb 24, 2016 · 6 comments
Closed
Tracked by #18824

BUG: datetimelike subtract incorrect when broadcasting #12437

toobaz opened this issue Feb 24, 2016 · 6 comments
Labels
Bug Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Timedelta Timedelta data type

Comments

@toobaz
Copy link
Member

toobaz commented Feb 24, 2016

In [2]: base, step = 10**15, 10**14

In [3]: data = range(base, base+3*step, step)

In [4]: df = pd.DataFrame({i : data for i in range(3)}).astype('datetime64[ns]')

In [5]: s = pd.Series(data).astype('datetime64[ns]')

In [6]: df
Out[6]: 
                    0                   1                   2
0 1970-01-12 13:46:40 1970-01-12 13:46:40 1970-01-12 13:46:40
1 1970-01-13 17:33:20 1970-01-13 17:33:20 1970-01-13 17:33:20
2 1970-01-14 21:20:00 1970-01-14 21:20:00 1970-01-14 21:20:00

In [7]: (df - s)[0]
Out[7]: 
0   1970-01-01 00:00:00
1   1970-01-02 03:46:40
2   1970-01-03 07:33:20
Name: 0, dtype: datetime64[ns]

In [8]: (df[0] - s[0])
Out[8]: 
0   0 days 00:00:00
1   1 days 03:46:40
2   2 days 07:33:20
Name: 0, dtype: timedelta64[ns]

I would expect the two to give the same result (timedelta64[ns]).

In [9]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.10.final.0
python-bits: 64
OS: Linux
OS-release: 4.3.0-1-amd64
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: it_IT.utf8

pandas: 0.18.0rc1+35.g4048193
nose: 1.3.6
pip: 1.5.6
setuptools: 18.4
Cython: 0.23.2
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.8.0.dev0+755fa81
xarray: None
IPython: 2.4.1
sphinx: 1.3.1
patsy: 0.3.0-dev
dateutil: 2.2
pytz: 2012c
blosc: None
bottleneck: None
tables: 3.2.2
numexpr: 2.4.3
matplotlib: 1.5.0rc2
openpyxl: None
xlrd: 0.9.4
xlwt: 0.7.5
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.0
html5lib: 0.999
httplib2: 0.9.1
apiclient: None
sqlalchemy: 1.0.11
pymysql: None
psycopg2: 2.6.1 (dt dec mx pq3 ext lo64)
jinja2: 2.8
@kawochen
Copy link
Contributor

exists in 0.17.1 as well

@jreback
Copy link
Contributor

jreback commented Feb 24, 2016

xref: #8554, #7439

I thought we already had an issue for this.

You need to specify how to broadcast.

In [26]: df.sub(s,axis=0)
Out[26]: 
       0      1      2
0 0 days 0 days 0 days
1 0 days 0 days 0 days
2 0 days 0 days 0 days

# this is wrong
In [27]: df.sub(s,axis=1)
Out[27]: 
                    0                   1                   2
0 1970-01-01 00:00:00 1969-12-30 20:13:20 1969-12-29 16:26:40
1 1970-01-02 03:46:40 1970-01-01 00:00:00 1969-12-30 20:13:20
2 1970-01-03 07:33:20 1970-01-02 03:46:40 1970-01-01 00:00:00

@jreback
Copy link
Contributor

jreback commented Feb 24, 2016

so [27] is a bug.

@jreback jreback added Bug Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Timedelta Timedelta data type Difficulty Intermediate labels Feb 24, 2016
@jreback jreback added this to the 0.18.1 milestone Feb 24, 2016
@jreback jreback changed the title Row-wise subtraction of datetime returns datetime instead than timedelta BUG: datetimelike subtract incorrect when broadcasting Feb 24, 2016
@jreback jreback modified the milestones: 0.18.2, 0.18.1 Apr 25, 2016
@jreback jreback modified the milestones: 0.19.0, Next Major Release Sep 28, 2016
@jbrockmendel
Copy link
Member

Since #18784 is closed, let's make it explicit here: __eq__ is also wrong.

@jbrockmendel
Copy link
Member

This now works. Most likely closed by #22163.

@jbrockmendel
Copy link
Member

@jreback closeable?

@jreback jreback closed this as completed Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

4 participants