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

Broadcasting bug with datetime.date index? #2304

Closed
mcobzarenco opened this issue Nov 20, 2012 · 3 comments
Closed

Broadcasting bug with datetime.date index? #2304

mcobzarenco opened this issue Nov 20, 2012 · 3 comments
Labels
Testing pandas testing functions or related to the test suite
Milestone

Comments

@mcobzarenco
Copy link

Guys,

It seems to be a problem with broadcasting when having a datetime.date index, do you know what may be causing this?

Example:

index = index=[datetime.date(2012, 1, 1), datetime.date(2012, 1, 2)]
columns=['a', 'b']
df = pandas.DataFrame([[1., 2.], [3., 4.]], index, columns)

>>> print( df.mean(1) )
2012-01-01    1.5
2012-01-02    3.5

>>> print( (df - df.mean(1)).to_string() )
             a   b  2012-01-01  2012-01-02
2012-01-01 NaN NaN         NaN         NaN
2012-01-02 NaN NaN         NaN         NaN

The columns somehow end up being the union of the inital columns and the index. The above code works OK when using datetime.datetime instead.

Many thanks,
Marius

@changhiskhan
Copy link
Contributor

Try df.sub(df.mean(1), axis=0) as a workaround.

By default it's suppose to broadcast over the columns, except in the case of datetimes where it broadcasts over the index by default because it's such a common operation. I think we should expand it to cover dates and times as well, @wesm what do you think? Purist in me says maybe get rid of this hack altogether, but the use case is compelling

@wesm
Copy link
Member

wesm commented Nov 21, 2012

Binary ops between DataFrame of time series and a single time series has been special-cased to go column-by-column. This is some serious legacy stuff from pandas 0.1 and should probably receive a deprecation message in 0.10, to get users to change their code to use one of the explicit functions

@changhiskhan
Copy link
Contributor

Wow, I didn't know it went THAT far back...not sure how much legacy code is built on that assumption. Probably going to make a certain group of devs at a certain company fairly unhappy.

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

No branches or pull requests

3 participants