def shard_df_on_index(df, divisions):
 if isinstance(divisions, Iterator):
  divisions = list(divisions)
 if (not len(divisions)):
  (yield df)
 else:
  divisions = np.array(divisions)
  df = df.sort_index()
  index = df.index
  if is_categorical_dtype(index):
   index = index.as_ordered()
  indices = index.searchsorted(divisions)
  (yield df.iloc[:indices[0]])
  for i in range((len(indices) - 1)):
   (yield df.iloc[indices[i]:indices[(i + 1)]])
  (yield df.iloc[indices[(-1)]:])

def shard_df_on_index ( df , divisions ) : if isinstance ( divisions , Iterator ) : divisions = list ( divisions ) if ( not len ( divisions ) ) : ( yield df ) else : divisions = np . array ( divisions ) df = df . sort_index ( ) index = df . index if is_categorical_dtype ( index ) : index = index . as_ordered ( ) indices = index . searchsorted ( divisions ) ( yield df . iloc [ : indices [ 0 ] ] ) for i in range ( ( len ( indices ) - 1 ) ) : ( yield df . iloc [ indices [ i ] : indices [ ( i + 1 ) ] ] ) ( yield df . iloc [ indices [ ( - 1 ) ] : ] )
shard a dataframe by ranges on its index examples .