-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
Description
Hi. Not sure if it is a bug, or something which needs to be clarified.
Consider the code
s = pd.Series(np.arange(0,5), index=pd.date_range('20131027', periods=5, freq='1H', tz='Europe/Berlin'))
s.tz_convert("UTC", copy=False)
s
index is still the same as before. If i do the same for frames.
d = pd.DataFrame(s)
d.tz_convert("UTC", copy=False)
This time index of d
has changed. From the code it is not clear if DataFrame
is doing the right thing either.
So is it a bug or is it just inconsistent, or is it an intention?
Update:
In [1]: s = pd.Series(np.arange(0,5), index=pd.date_range('20131027', periods=5, freq='1H', tz='Europe/Berlin'))
s.tz_convert("UTC", copy=False)
Out[1]:
2013-10-26 22:00:00+00:00 0
2013-10-26 23:00:00+00:00 1
2013-10-27 00:00:00+00:00 2
2013-10-27 01:00:00+00:00 3
2013-10-27 02:00:00+00:00 4
Freq: H, dtype: int32
In [2]: s
Out[2]:
2013-10-27 00:00:00+02:00 0
2013-10-27 01:00:00+02:00 1
2013-10-27 02:00:00+02:00 2
2013-10-27 02:00:00+01:00 3
2013-10-27 03:00:00+01:00 4
Freq: H, dtype: int32
In [3]: d = pd.DataFrame(s)
d.tz_convert("UTC", copy=False)
Out[3]:
2013-10-26 22:00:00+00:00 0
2013-10-26 23:00:00+00:00 1
2013-10-27 00:00:00+00:00 2
2013-10-27 01:00:00+00:00 3
2013-10-27 02:00:00+00:00 4
In [214]: d
Out[214]:
2013-10-26 22:00:00+00:00 0
2013-10-26 23:00:00+00:00 1
2013-10-27 00:00:00+00:00 2
2013-10-27 01:00:00+00:00 3
2013-10-27 02:00:00+00:00 4
Activity
jreback commentedon Feb 12, 2014
looks ok in 0.13.1..
alexchamberlain commentedon Feb 12, 2014
If you inspect
s
. it hasn't changed under 0.13.1.jreback commentedon Feb 12, 2014
why would you expect
s
to change? most pandas methods return a new objectthe
copy
flag is just tries not to actually copy the index if it doesn't need to; in this case it does so its irrelevanthendrics commentedon Feb 12, 2014
DataFrame
does change though. If you inspectd
it will have a new index. It might be that index is part of the data in theDataFrame
, it's just the behaviour is inconsistent.Updated the comment above with the output.
jreback commentedon Feb 12, 2014
ahh..ok....will mark as a bug...thanks for the report
jreback commentedon Feb 18, 2014
@hendrics
pls run this again on master....I am pretty sure this is fixed (and if you want to add an explicty test for this, would be gr8)
see here: b1687b8
[-]tz_convert with copy=False behaves differently and unexpectedly for Series and DataFrame[/-][+]DataFrame.tz_convert with copy=False modifies original data[/+]mroeschke commentedon Jan 4, 2019
The Series case is actually wrong now as well.
[-]DataFrame.tz_convert with copy=False modifies original data[/-][+]DataFrame/Series.tz_convert with copy=False modifies original data[/+]