concat of tz series and no tz results in attribute error. #11755

Closed
varun-kr opened this Issue Dec 3, 2015 · 9 comments

Comments

Projects
None yet
3 participants
Contributor

varun-kr commented Dec 3, 2015

import pandas as pd
x = pd.Series(pd.date_range('20151124 10:00', '20151124 11:00', freq = '1h', tz = "UTC") )
y = pd.Series(pd.date_range('2012-01-01', '2012-01-03'))
pd.concat([x,y])

AttributeError: 'numpy.ndarray' object has no attribute 'tz_localize'

Is it a bug or not supported ?

varun-kr changed the title from concat of tz series and no tz results in attribute error. Is it a bug ? to concat of tz series and no tz results in attribute error. Dec 3, 2015

Contributor

jreback commented Dec 3, 2015

this is realted to #11705

this should work, but both series get converted to object dtype first

so this is a bug in there somewhere

jreback added this to the 0.18.0 milestone Dec 3, 2015

Contributor

varun-kr commented Dec 20, 2015

@jreback If we convert to object , we loose the timezone information. Is it the best way to handle this ?

Contributor

jreback commented Dec 21, 2015

tz that compat iow they match should be preserved
if no tz then they are returned as naive
if things are mixed then they get converts to object

this already exists - this is just missing a conversion somewhere I think - if u add tests as I suggest it should be easy to figure out

Contributor

varun-kr commented Dec 22, 2015

@jreback
I tried converting datetimenz and datetime to objects. But it does not help.
For the above mentioned example, np.concatenate() returns a datetime array

[datetime.datetime(2015, 11, 24, 10, 0)
 datetime.datetime(2015, 11, 24, 11, 0) 
datetime.datetime(2012, 1, 1, 0, 0)
 datetime.datetime(2012, 1, 2, 0, 0)]

Creating a series will always return datetime series not object.

Output

0   2015-11-24 10:00:00
1   2015-11-24 11:00:00
0   2012-01-01 00:00:00
1   2012-01-02 00:00:00
dtype: datetime64[ns]

Any suggestions?

Contributor

jreback commented Dec 22, 2015

just step thru the code
FYI - we rarely use native numpy routines when non numeric types - they don't have things well

Contributor

varun-kr commented Dec 23, 2015

@jreback In this group by test case we expect a datetime64[ns] series . "combining multiple / different timezones yields UTC". And in the above example we expect an object . Is it not an inconsistency ? Should it be datetime64[ns] ?

Contributor

jreback commented Dec 23, 2015

see if you can find when that groupby behavior was put in place. IIRC this was though to be more natural.

cc @sinhrks

but as I look now, we have a policy of only combing the exact same timezones, and converting to object dtype otherwise. There is an exception though because whenever you convert to an actual numpy array, and you have all uniform dtypes then you will get converted to UTC then to naive.

So the answer to your question, is that we may need to change this groupby test case to conform. (and possibly note as an API change to clean this up).

Member

sinhrks commented Dec 24, 2015

This is related to #11455 also.

IIRC, I had test failues in the same groupby tests when I tried to fix #11455. And it is also related to current DatetimeIndex creation process. I'll revisit this to find more detail.

@jreback jreback modified the milestone: 0.18.1, 0.18.0 Feb 10, 2016

Contributor

jreback commented Feb 10, 2016

was closed by #12195

jreback closed this Feb 10, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment