File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -970,17 +970,16 @@ def get_loc(self, key):
970
970
except KeyError :
971
971
try :
972
972
return self ._get_string_slice (key )
973
- except (TypeError , KeyError ):
973
+ except (TypeError , KeyError , ValueError ):
974
974
pass
975
975
976
976
if isinstance (key , time ):
977
977
return self ._indices_at_time (key )
978
978
979
- stamp = Timestamp (key )
980
979
try :
981
- return self ._engine .get_loc (stamp )
982
- except KeyError :
983
- raise KeyError (stamp )
980
+ return self ._engine .get_loc (Timestamp ( key ) )
981
+ except ( KeyError , ValueError ) :
982
+ raise KeyError (key )
984
983
985
984
def _indices_at_time (self , key ):
986
985
from dateutil .parser import parse
Original file line number Diff line number Diff line change @@ -913,6 +913,21 @@ def test_set_dataframe_column_ns_dtype(self):
913
913
x [0 ] = to_datetime (x [0 ])
914
914
self .assert_ (x [0 ].dtype == np .dtype ('M8[ns]' ))
915
915
916
+ def test_groupby_count_dateparseerror (self ):
917
+ from pandas import *
918
+
919
+ dr = date_range (start = '1/1/2012' , freq = '5min' , periods = 10 )
920
+
921
+ # BAD Example, datetimes first
922
+ s = Series (np .arange (10 ), index = [dr , range (10 )])
923
+ grouped = s .groupby (lambda x : x [1 ] % 2 == 0 )
924
+ result = grouped .count ()
925
+
926
+ s = Series (np .arange (10 ), index = [range (10 ), dr ])
927
+ grouped = s .groupby (lambda x : x [0 ] % 2 == 0 )
928
+ expected = grouped .count ()
929
+
930
+ assert_series_equal (result , expected )
916
931
917
932
def _simple_ts (start , end , freq = 'D' ):
918
933
rng = date_range (start , end , freq = freq )
You can’t perform that action at this time.
0 commit comments