how to group cftime coordinate by week?
              
              #6375
            
            
              
                
                  
                  
                    Answered
                  
                  by
                    spencerkclark
                  
              
          
                  
                    
                      aaronspring
                    
                  
                
                  asked this question in
                Q&A
              
            -
| Suppose you have to work with  Is there a  import xarray as xr
xr.__version__ # '2022.3.0'
import cftime
cftime.__version__ # '1.6.0'
ds = xr.tutorial.load_dataset('air_temperature', use_cftime=True)
ds.convert_calendar(calendar='standard').groupby('time.week').mean() # works
ds.groupby('time.week').mean() # AttributeError: 'CFTimeIndex' object has no attribute 'isocalendar'
ds.groupby(ds.time.dt.isocalendar().week).mean() # AttributeError: 'CFTimeIndex' object has no attribute 'isocalendar'
ds = xr.tutorial.load_dataset('air_temperature', use_cftime=False)
ds.groupby('time.week').mean() # FutureWarning: dt.weekofyear and dt.week have been deprecated. Please use dt.isocalendar().week instead.
ds.groupby(ds.time.dt.isocalendar().week).mean() # works | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            spencerkclark
          
      
      
        Mar 18, 2022 
      
    
    Replies: 1 comment
-
| The primary reason is that  | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        aaronspring
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
The primary reason is that
cftime.datetimeobjects do not implement anisocalendarmethod (seedatetime.date.isocalendarfor more details). You could consider raising an issue in thecftimerepo. If they did, it would make it pretty easy to enable in xarray.