@@ -1072,6 +1072,25 @@ def test_loc_setitem_consistency(self):
1072
1072
df ['x' ] = 1
1073
1073
assert_frame_equal (df ,expected )
1074
1074
1075
+ # .loc[:,column] setting with slice == len of the column
1076
+ # GH10408
1077
+ data = """Level_0,,,Respondent,Respondent,Respondent,OtherCat,OtherCat
1078
+ Level_1,,,Something,StartDate,EndDate,Yes/No,SomethingElse
1079
+ Region,Site,RespondentID,,,,,
1080
+ Region_1,Site_1,3987227376,A,5/25/2015 10:59,5/25/2015 11:22,Yes,
1081
+ Region_1,Site_1,3980680971,A,5/21/2015 9:40,5/21/2015 9:52,Yes,Yes
1082
+ Region_1,Site_2,3977723249,A,5/20/2015 8:27,5/20/2015 8:41,Yes,
1083
+ Region_1,Site_2,3977723089,A,5/20/2015 8:33,5/20/2015 9:09,Yes,No"""
1084
+
1085
+ df = pd .read_csv (StringIO (data ),header = [0 ,1 ], index_col = [0 ,1 ,2 ])
1086
+ df .loc [:,('Respondent' ,'StartDate' )] = pd .to_datetime (df .loc [:,('Respondent' ,'StartDate' )])
1087
+ df .loc [:,('Respondent' ,'EndDate' )] = pd .to_datetime (df .loc [:,('Respondent' ,'EndDate' )])
1088
+ df .loc [:,('Respondent' ,'Duration' )] = df .loc [:,('Respondent' ,'EndDate' )] - df .loc [:,('Respondent' ,'StartDate' )]
1089
+
1090
+ df .loc [:,('Respondent' ,'Duration' )] = df .loc [:,('Respondent' ,'Duration' )].astype ('timedelta64[s]' )
1091
+ expected = Series ([1380 ,720 ,840 ,2160. ],index = df .index ,name = ('Respondent' ,'Duration' ))
1092
+ assert_series_equal (df [('Respondent' ,'Duration' )],expected )
1093
+
1075
1094
def test_loc_setitem_frame (self ):
1076
1095
df = self .frame_labels
1077
1096
@@ -2331,27 +2350,27 @@ def test_setitem_dtype_upcast(self):
2331
2350
assert_frame_equal (df ,expected )
2332
2351
2333
2352
# GH10280
2334
- df = DataFrame (np .arange (6 ,dtype = 'int64' ).reshape (2 , 3 ),
2353
+ df = DataFrame (np .arange (6 ,dtype = 'int64' ).reshape (2 , 3 ),
2335
2354
index = list ('ab' ),
2336
2355
columns = ['foo' , 'bar' , 'baz' ])
2337
2356
2338
2357
for val in [3.14 , 'wxyz' ]:
2339
2358
left = df .copy ()
2340
2359
left .loc ['a' , 'bar' ] = val
2341
- right = DataFrame ([[0 , val , 2 ], [3 , 4 , 5 ]],
2360
+ right = DataFrame ([[0 , val , 2 ], [3 , 4 , 5 ]],
2342
2361
index = list ('ab' ),
2343
2362
columns = ['foo' , 'bar' , 'baz' ])
2344
2363
2345
2364
assert_frame_equal (left , right )
2346
2365
self .assertTrue (com .is_integer_dtype (left ['foo' ]))
2347
2366
self .assertTrue (com .is_integer_dtype (left ['baz' ]))
2348
2367
2349
- left = DataFrame (np .arange (6 ,dtype = 'int64' ).reshape (2 , 3 ) / 10.0 ,
2368
+ left = DataFrame (np .arange (6 ,dtype = 'int64' ).reshape (2 , 3 ) / 10.0 ,
2350
2369
index = list ('ab' ),
2351
2370
columns = ['foo' , 'bar' , 'baz' ])
2352
2371
left .loc ['a' , 'bar' ] = 'wxyz'
2353
2372
2354
- right = DataFrame ([[0 , 'wxyz' , .2 ], [.3 , .4 , .5 ]],
2373
+ right = DataFrame ([[0 , 'wxyz' , .2 ], [.3 , .4 , .5 ]],
2355
2374
index = list ('ab' ),
2356
2375
columns = ['foo' , 'bar' , 'baz' ])
2357
2376
0 commit comments