- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 19.2k
 
DEPR: DataFrame.median/mean with numeric_only=None and dt64 columns #49250
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
      
      
    
      
        
          +13
        
        
          −39
        
        
          
        
      
    
  
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -73,14 +73,13 @@ def assert_stat_op_calc( | |
| f = getattr(frame, opname) | ||
| 
     | 
||
| if check_dates: | ||
| expected_warning = FutureWarning if opname in ["mean", "median"] else None | ||
| df = DataFrame({"b": date_range("1/1/2001", periods=2)}) | ||
| with tm.assert_produces_warning(expected_warning): | ||
| with tm.assert_produces_warning(None): | ||
| result = getattr(df, opname)() | ||
| assert isinstance(result, Series) | ||
| 
     | 
||
| df["a"] = range(len(df)) | ||
| with tm.assert_produces_warning(expected_warning): | ||
| with tm.assert_produces_warning(None): | ||
| result = getattr(df, opname)() | ||
| assert isinstance(result, Series) | ||
| assert len(result) | ||
| 
          
            
          
           | 
    @@ -390,21 +389,20 @@ def test_nunique(self): | |
| def test_mean_mixed_datetime_numeric(self, tz): | ||
| # https://github.com/pandas-dev/pandas/issues/24752 | ||
| df = DataFrame({"A": [1, 1], "B": [Timestamp("2000", tz=tz)] * 2}) | ||
| with tm.assert_produces_warning(FutureWarning): | ||
| result = df.mean() | ||
| expected = Series([1.0], index=["A"]) | ||
| result = df.mean() | ||
| expected = Series([1.0, Timestamp("2000", tz=tz)], index=["A", "B"]) | ||
| tm.assert_series_equal(result, expected) | ||
| 
     | 
||
| @pytest.mark.parametrize("tz", [None, "UTC"]) | ||
| def test_mean_excludes_datetimes(self, tz): | ||
| # https://github.com/pandas-dev/pandas/issues/24752 | ||
| # Our long-term desired behavior is unclear, but the behavior in | ||
| # 0.24.0rc1 was buggy. | ||
                
       | 
||
| # As of 2.0 with numeric_only=None we do *not* drop datetime columns | ||
| df = DataFrame({"A": [Timestamp("2000", tz=tz)] * 2}) | ||
| with tm.assert_produces_warning(FutureWarning): | ||
| result = df.mean() | ||
| result = df.mean() | ||
| 
     | 
||
| expected = Series(dtype=np.float64) | ||
| expected = Series([Timestamp("2000", tz=tz)], index=["A"]) | ||
| tm.assert_series_equal(result, expected) | ||
| 
     | 
||
| def test_mean_mixed_string_decimal(self): | ||
| 
          
            
          
           | 
    @@ -857,6 +855,7 @@ def test_mean_corner(self, float_frame, float_string_frame): | |
| def test_mean_datetimelike(self): | ||
| # GH#24757 check that datetimelike are excluded by default, handled | ||
| # correctly with numeric_only=True | ||
| # As of 2.0, datetimelike are *not* excluded with numeric_only=None | ||
| 
     | 
||
| df = DataFrame( | ||
| { | ||
| 
        
          
        
         | 
    @@ -870,10 +869,9 @@ def test_mean_datetimelike(self): | |
| expected = Series({"A": 1.0}) | ||
| tm.assert_series_equal(result, expected) | ||
| 
     | 
||
| with tm.assert_produces_warning(FutureWarning): | ||
| # in the future datetime columns will be included | ||
| with tm.assert_produces_warning(FutureWarning, match="Select only valid"): | ||
| result = df.mean() | ||
| expected = Series({"A": 1.0, "C": df.loc[1, "C"]}) | ||
| expected = Series({"A": 1.0, "B": df.loc[1, "B"], "C": df.loc[1, "C"]}) | ||
| tm.assert_series_equal(result, expected) | ||
| 
     | 
||
| def test_mean_datetimelike_numeric_only_false(self): | ||
| 
          
            
          
           | 
    ||
  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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we should rename this test (starting L397 here) as we're no longer testing that mean excludes datetimes.