@@ -832,113 +832,6 @@ def compare(result, expected):
832
832
result2 = s .loc [0 :3 ]
833
833
tm .assert_series_equal (result1 , result2 )
834
834
835
- def test_indexing_with_datetime_tz (self ):
836
-
837
- # 8260
838
- # support datetime64 with tz
839
-
840
- idx = Index (date_range ('20130101' , periods = 3 , tz = 'US/Eastern' ),
841
- name = 'foo' )
842
- dr = date_range ('20130110' , periods = 3 )
843
- df = DataFrame ({'A' : idx , 'B' : dr })
844
- df ['C' ] = idx
845
- df .iloc [1 , 1 ] = pd .NaT
846
- df .iloc [1 , 2 ] = pd .NaT
847
-
848
- # indexing
849
- result = df .iloc [1 ]
850
- expected = Series ([Timestamp ('2013-01-02 00:00:00-0500' ,
851
- tz = 'US/Eastern' ), np .nan , np .nan ],
852
- index = list ('ABC' ), dtype = 'object' , name = 1 )
853
- tm .assert_series_equal (result , expected )
854
- result = df .loc [1 ]
855
- expected = Series ([Timestamp ('2013-01-02 00:00:00-0500' ,
856
- tz = 'US/Eastern' ), np .nan , np .nan ],
857
- index = list ('ABC' ), dtype = 'object' , name = 1 )
858
- tm .assert_series_equal (result , expected )
859
-
860
- # indexing - fast_xs
861
- df = DataFrame ({'a' : date_range ('2014-01-01' , periods = 10 , tz = 'UTC' )})
862
- result = df .iloc [5 ]
863
- expected = Timestamp ('2014-01-06 00:00:00+0000' , tz = 'UTC' , freq = 'D' )
864
- self .assertEqual (result , expected )
865
-
866
- result = df .loc [5 ]
867
- self .assertEqual (result , expected )
868
-
869
- # indexing - boolean
870
- result = df [df .a > df .a [3 ]]
871
- expected = df .iloc [4 :]
872
- tm .assert_frame_equal (result , expected )
873
-
874
- # indexing - setting an element
875
- df = DataFrame (data = pd .to_datetime (
876
- ['2015-03-30 20:12:32' , '2015-03-12 00:11:11' ]), columns = ['time' ])
877
- df ['new_col' ] = ['new' , 'old' ]
878
- df .time = df .set_index ('time' ).index .tz_localize ('UTC' )
879
- v = df [df .new_col == 'new' ].set_index ('time' ).index .tz_convert (
880
- 'US/Pacific' )
881
-
882
- # trying to set a single element on a part of a different timezone
883
- def f ():
884
- df .loc [df .new_col == 'new' , 'time' ] = v
885
-
886
- self .assertRaises (ValueError , f )
887
-
888
- v = df .loc [df .new_col == 'new' , 'time' ] + pd .Timedelta ('1s' )
889
- df .loc [df .new_col == 'new' , 'time' ] = v
890
- tm .assert_series_equal (df .loc [df .new_col == 'new' , 'time' ], v )
891
-
892
- def test_indexing_with_datetimeindex_tz (self ):
893
-
894
- # GH 12050
895
- # indexing on a series with a datetimeindex with tz
896
- index = pd .date_range ('2015-01-01' , periods = 2 , tz = 'utc' )
897
-
898
- ser = pd .Series (range (2 ), index = index ,
899
- dtype = 'int64' )
900
-
901
- # list-like indexing
902
-
903
- for sel in (index , list (index )):
904
- # getitem
905
- tm .assert_series_equal (ser [sel ], ser )
906
-
907
- # setitem
908
- result = ser .copy ()
909
- result [sel ] = 1
910
- expected = pd .Series (1 , index = index )
911
- tm .assert_series_equal (result , expected )
912
-
913
- # .loc getitem
914
- tm .assert_series_equal (ser .loc [sel ], ser )
915
-
916
- # .loc setitem
917
- result = ser .copy ()
918
- result .loc [sel ] = 1
919
- expected = pd .Series (1 , index = index )
920
- tm .assert_series_equal (result , expected )
921
-
922
- # single element indexing
923
-
924
- # getitem
925
- self .assertEqual (ser [index [1 ]], 1 )
926
-
927
- # setitem
928
- result = ser .copy ()
929
- result [index [1 ]] = 5
930
- expected = pd .Series ([0 , 5 ], index = index )
931
- tm .assert_series_equal (result , expected )
932
-
933
- # .loc getitem
934
- self .assertEqual (ser .loc [index [1 ]], 1 )
935
-
936
- # .loc setitem
937
- result = ser .copy ()
938
- result .loc [index [1 ]] = 5
939
- expected = pd .Series ([0 , 5 ], index = index )
940
- tm .assert_series_equal (result , expected )
941
-
942
835
def test_loc_setitem_dups (self ):
943
836
944
837
# GH 6541
@@ -2917,36 +2810,6 @@ def f():
2917
2810
dtype = 'float64' )
2918
2811
tm .assert_frame_equal (df , exp )
2919
2812
2920
- def test_partial_setting_with_datetimelike_dtype (self ):
2921
-
2922
- # GH9478
2923
- # a datetimeindex alignment issue with partial setting
2924
- df = pd .DataFrame (np .arange (6. ).reshape (3 , 2 ), columns = list ('AB' ),
2925
- index = pd .date_range ('1/1/2000' , periods = 3 ,
2926
- freq = '1H' ))
2927
- expected = df .copy ()
2928
- expected ['C' ] = [expected .index [0 ]] + [pd .NaT , pd .NaT ]
2929
-
2930
- mask = df .A < 1
2931
- df .loc [mask , 'C' ] = df .loc [mask ].index
2932
- tm .assert_frame_equal (df , expected )
2933
-
2934
- def test_loc_setitem_datetime (self ):
2935
-
2936
- # GH 9516
2937
- dt1 = Timestamp ('20130101 09:00:00' )
2938
- dt2 = Timestamp ('20130101 10:00:00' )
2939
-
2940
- for conv in [lambda x : x , lambda x : x .to_datetime64 (),
2941
- lambda x : x .to_pydatetime (), lambda x : np .datetime64 (x )]:
2942
-
2943
- df = pd .DataFrame ()
2944
- df .loc [conv (dt1 ), 'one' ] = 100
2945
- df .loc [conv (dt2 ), 'one' ] = 200
2946
-
2947
- expected = DataFrame ({'one' : [100.0 , 200.0 ]}, index = [dt1 , dt2 ])
2948
- tm .assert_frame_equal (df , expected )
2949
-
2950
2813
def test_series_partial_set (self ):
2951
2814
# partial set with new index
2952
2815
# Regression from GH4825
@@ -3081,54 +2944,6 @@ def test_series_partial_set_with_name(self):
3081
2944
result = ser .iloc [[1 , 1 , 0 , 0 ]]
3082
2945
tm .assert_series_equal (result , expected , check_index_type = True )
3083
2946
3084
- def test_series_partial_set_datetime (self ):
3085
- # GH 11497
3086
-
3087
- idx = date_range ('2011-01-01' , '2011-01-02' , freq = 'D' , name = 'idx' )
3088
- ser = Series ([0.1 , 0.2 ], index = idx , name = 's' )
3089
-
3090
- result = ser .loc [[Timestamp ('2011-01-01' ), Timestamp ('2011-01-02' )]]
3091
- exp = Series ([0.1 , 0.2 ], index = idx , name = 's' )
3092
- tm .assert_series_equal (result , exp , check_index_type = True )
3093
-
3094
- keys = [Timestamp ('2011-01-02' ), Timestamp ('2011-01-02' ),
3095
- Timestamp ('2011-01-01' )]
3096
- exp = Series ([0.2 , 0.2 , 0.1 ], index = pd .DatetimeIndex (keys , name = 'idx' ),
3097
- name = 's' )
3098
- tm .assert_series_equal (ser .loc [keys ], exp , check_index_type = True )
3099
-
3100
- keys = [Timestamp ('2011-01-03' ), Timestamp ('2011-01-02' ),
3101
- Timestamp ('2011-01-03' )]
3102
- exp = Series ([np .nan , 0.2 , np .nan ],
3103
- index = pd .DatetimeIndex (keys , name = 'idx' ), name = 's' )
3104
- tm .assert_series_equal (ser .loc [keys ], exp , check_index_type = True )
3105
-
3106
- def test_series_partial_set_period (self ):
3107
- # GH 11497
3108
-
3109
- idx = pd .period_range ('2011-01-01' , '2011-01-02' , freq = 'D' , name = 'idx' )
3110
- ser = Series ([0.1 , 0.2 ], index = idx , name = 's' )
3111
-
3112
- result = ser .loc [[pd .Period ('2011-01-01' , freq = 'D' ),
3113
- pd .Period ('2011-01-02' , freq = 'D' )]]
3114
- exp = Series ([0.1 , 0.2 ], index = idx , name = 's' )
3115
- tm .assert_series_equal (result , exp , check_index_type = True )
3116
-
3117
- keys = [pd .Period ('2011-01-02' , freq = 'D' ),
3118
- pd .Period ('2011-01-02' , freq = 'D' ),
3119
- pd .Period ('2011-01-01' , freq = 'D' )]
3120
- exp = Series ([0.2 , 0.2 , 0.1 ], index = pd .PeriodIndex (keys , name = 'idx' ),
3121
- name = 's' )
3122
- tm .assert_series_equal (ser .loc [keys ], exp , check_index_type = True )
3123
-
3124
- keys = [pd .Period ('2011-01-03' , freq = 'D' ),
3125
- pd .Period ('2011-01-02' , freq = 'D' ),
3126
- pd .Period ('2011-01-03' , freq = 'D' )]
3127
- exp = Series ([np .nan , 0.2 , np .nan ],
3128
- index = pd .PeriodIndex (keys , name = 'idx' ), name = 's' )
3129
- result = ser .loc [keys ]
3130
- tm .assert_series_equal (result , exp )
3131
-
3132
2947
def test_partial_set_invalid (self ):
3133
2948
3134
2949
# GH 4940
0 commit comments