- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 19.2k
 
API: Make describe changes backwards compatible #34798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      05bd224
              
                API: Make describe changes backwards compatible
              
              
                TomAugspurger 27e9768
              
                doctest
              
              
                TomAugspurger 12b4ae2
              
                Merge remote-tracking branch 'upstream/master' into 33903-describe
              
              
                TomAugspurger 53cfee8
              
                whatsnew
              
              
                TomAugspurger 6586280
              
                fixups
              
              
                TomAugspurger 0222e76
              
                fixup
              
              
                TomAugspurger 5be87df
              
                Merge branch 'master' into 33903-describe
              
              
                jreback c6d5454
              
                Merge remote-tracking branch 'upstream/master' into 33903-describe
              
              
                TomAugspurger 166f6f4
              
                doc fixup
              
              
                TomAugspurger 122e2f5
              
                newline
              
              
                TomAugspurger File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -267,7 +267,69 @@ def test_describe_tz_values(self, tz_naive_fixture): | |
| }, | ||
| index=["count", "mean", "min", "25%", "50%", "75%", "max", "std"], | ||
| ) | ||
| result = df.describe(include="all") | ||
| result = df.describe(include="all", datetime_is_numeric=True) | ||
| tm.assert_frame_equal(result, expected) | ||
| 
     | 
||
| def test_datetime_is_numeric_includes_datetime(self): | ||
| df = pd.DataFrame({"a": pd.date_range("2012", periods=3), "b": [1, 2, 3]}) | ||
| result = df.describe(datetime_is_numeric=True) | ||
| expected = pd.DataFrame( | ||
| { | ||
| "a": [ | ||
| 3, | ||
| pd.Timestamp("2012-01-02"), | ||
| pd.Timestamp("2012-01-01"), | ||
| pd.Timestamp("2012-01-01T12:00:00"), | ||
| pd.Timestamp("2012-01-02"), | ||
| pd.Timestamp("2012-01-02T12:00:00"), | ||
| pd.Timestamp("2012-01-03"), | ||
| np.nan, | ||
| ], | ||
| "b": [3, 2, 1, 1.5, 2, 2.5, 3, 1], | ||
| }, | ||
| index=["count", "mean", "min", "25%", "50%", "75%", "max", "std"], | ||
| ) | ||
| tm.assert_frame_equal(result, expected) | ||
| 
     | 
||
| def test_describe_tz_values2(self): | ||
| tz = "CET" | ||
| s1 = Series(range(5)) | ||
| start = Timestamp(2018, 1, 1) | ||
| end = Timestamp(2018, 1, 5) | ||
| s2 = Series(date_range(start, end, tz=tz)) | ||
| df = pd.DataFrame({"s1": s1, "s2": s2}) | ||
| 
     | 
||
| s1_ = s1.describe() | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make as a separate test  | 
||
| s2_ = pd.Series( | ||
| [ | ||
| 5, | ||
| 5, | ||
| s2.value_counts().index[0], | ||
| 1, | ||
| start.tz_localize(tz), | ||
| end.tz_localize(tz), | ||
| ], | ||
| index=["count", "unique", "top", "freq", "first", "last"], | ||
| ) | ||
| idx = [ | ||
| "count", | ||
| "unique", | ||
| "top", | ||
| "freq", | ||
| "first", | ||
| "last", | ||
| "mean", | ||
| "std", | ||
| "min", | ||
| "25%", | ||
| "50%", | ||
| "75%", | ||
| "max", | ||
| ] | ||
| expected = pd.concat([s1_, s2_], axis=1, keys=["s1", "s2"]).loc[idx] | ||
| 
     | 
||
| with tm.assert_produces_warning(FutureWarning): | ||
| result = df.describe(include="all") | ||
| tm.assert_frame_equal(result, expected) | ||
| 
     | 
||
| def test_describe_percentiles_integer_idx(self): | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -83,7 +83,7 @@ def test_describe_with_tz(self, tz_naive_fixture): | |
| start = Timestamp(2018, 1, 1) | ||
| end = Timestamp(2018, 1, 5) | ||
| s = Series(date_range(start, end, tz=tz), name=name) | ||
| result = s.describe() | ||
| result = s.describe(datetime_is_numeric=True) | ||
| expected = Series( | ||
| [ | ||
| 5, | ||
| 
        
          
        
         | 
    @@ -98,3 +98,43 @@ def test_describe_with_tz(self, tz_naive_fixture): | |
| index=["count", "mean", "min", "25%", "50%", "75%", "max"], | ||
| ) | ||
| tm.assert_series_equal(result, expected) | ||
| 
     | 
||
| def test_describe_with_tz_warns(self): | ||
| name = tz = "CET" | ||
| start = Timestamp(2018, 1, 1) | ||
| end = Timestamp(2018, 1, 5) | ||
| s = Series(date_range(start, end, tz=tz), name=name) | ||
| 
     | 
||
| with tm.assert_produces_warning(FutureWarning): | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same  | 
||
| result = s.describe() | ||
| 
     | 
||
| expected = Series( | ||
| [ | ||
| 5, | ||
| 5, | ||
| s.value_counts().index[0], | ||
| 1, | ||
| start.tz_localize(tz), | ||
| end.tz_localize(tz), | ||
| ], | ||
| name=name, | ||
| index=["count", "unique", "top", "freq", "first", "last"], | ||
| ) | ||
| tm.assert_series_equal(result, expected) | ||
| 
     | 
||
| def test_datetime_is_numeric_includes_datetime(self): | ||
| s = Series(date_range("2012", periods=3)) | ||
| result = s.describe(datetime_is_numeric=True) | ||
| expected = Series( | ||
| [ | ||
| 3, | ||
| Timestamp("2012-01-02"), | ||
| Timestamp("2012-01-01"), | ||
| Timestamp("2012-01-01T12:00:00"), | ||
| Timestamp("2012-01-02"), | ||
| Timestamp("2012-01-02T12:00:00"), | ||
| Timestamp("2012-01-03"), | ||
| ], | ||
| index=["count", "mean", "min", "25%", "50%", "75%", "max"], | ||
| ) | ||
| tm.assert_series_equal(result, expected) | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.