- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 19.2k
 
ENH: consistency of input args for boundaries (pd.date_range) #43504
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
      
      203733e
              
                Change date_range inclusive
              
              
                zyc09 05def22
              
                to use validate_inclusive in util
              
              
                zyc09 be085dd
              
                typing + docstring
              
              
                zyc09 ff0649c
              
                Move inclusive_endpoints_fixture to outer conftest
              
              
                zyc09 67015ff
              
                Rework Tests
              
              
                zyc09 e80329f
              
                remove line
              
              
                zyc09 245c50e
              
                Amend logic + factoring of tests
              
              
                zyc09 2c5d65d
              
                closed -> inclusive in tests
              
              
                zyc09 4b85743
              
                docstring grammar
              
              
                zyc09 eea0075
              
                Merge branch 'master' into bug/date-range
              
              
                attack68 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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
| 
          
            
          
           | 
    @@ -881,7 +881,8 @@ def date_range( | |
| tz=None, | ||
| normalize: bool = False, | ||
| name: Hashable = None, | ||
| closed=None, | ||
| closed: str | None | lib.NoDefault = lib.no_default, | ||
| inclusive: str | None = None, | ||
| **kwargs, | ||
| ) -> DatetimeIndex: | ||
| """ | ||
| 
          
            
          
           | 
    @@ -919,6 +920,14 @@ def date_range( | |
| closed : {None, 'left', 'right'}, optional | ||
| Make the interval closed with respect to the given frequency to | ||
| the 'left', 'right', or both sides (None, the default). | ||
| 
     | 
||
| .. deprecated:: 1.4.0 | ||
| Argument `closed` has been deprecated to standardize boundary inputs. | ||
| Use `inclusive` instead, to set each bound as closed or open. | ||
| inclusive : {"both", "neither", "left", "right"}, default "both" | ||
| Include boundaries; Whether to set each bound as closed or open. | ||
| 
     | 
||
| .. versionadded:: 1.4.0 | ||
| **kwargs | ||
| For compatibility. Has no effect on the result. | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -1029,6 +1038,28 @@ def date_range( | |
| DatetimeIndex(['2017-01-02', '2017-01-03', '2017-01-04'], | ||
| dtype='datetime64[ns]', freq='D') | ||
| """ | ||
| if inclusive is not None and not isinstance(closed, lib.NoDefault): | ||
| 
         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. its possible we would want to share this (across functoions), but ok here  | 
||
| raise ValueError( | ||
| "Deprecated argument `closed` cannot be passed" | ||
| "if argument `inclusive` is not None" | ||
| ) | ||
| elif not isinstance(closed, lib.NoDefault): | ||
| warnings.warn( | ||
| "Argument `closed` is deprecated in favor of `inclusive`.", | ||
| FutureWarning, | ||
| stacklevel=2, | ||
| ) | ||
| if closed is None: | ||
| inclusive = "both" | ||
| elif closed in ("left", "right"): | ||
| inclusive = closed | ||
| else: | ||
| raise ValueError( | ||
| "Argument `closed` has to be either 'left', 'right' or None" | ||
| ) | ||
| elif inclusive is None: | ||
| inclusive = "both" | ||
| 
     | 
||
| if freq is None and com.any_none(periods, start, end): | ||
| freq = "D" | ||
| 
     | 
||
| 
        
          
        
         | 
    @@ -1039,7 +1070,7 @@ def date_range( | |
| freq=freq, | ||
| tz=tz, | ||
| normalize=normalize, | ||
| closed=closed, | ||
| inclusive=inclusive, | ||
| **kwargs, | ||
| ) | ||
| return DatetimeIndex._simple_new(dtarr, name=name) | ||
| 
        
          
        
         | 
    @@ -1055,7 +1086,8 @@ def bdate_range( | |
| name: Hashable = None, | ||
| weekmask=None, | ||
| holidays=None, | ||
| closed=None, | ||
| closed: lib.NoDefault = lib.no_default, | ||
| inclusive: str | None = None, | ||
| **kwargs, | ||
| ) -> DatetimeIndex: | ||
| """ | ||
| 
          
            
          
           | 
    @@ -1090,6 +1122,14 @@ def bdate_range( | |
| closed : str, default None | ||
| Make the interval closed with respect to the given frequency to | ||
| the 'left', 'right', or both sides (None). | ||
| 
     | 
||
| .. deprecated:: 1.4.0 | ||
| Argument `closed` has been deprecated to standardize boundary inputs. | ||
| Use `inclusive` instead, to set each bound as closed or open. | ||
| inclusive : {"both", "neither", "left", "right"}, default "both" | ||
| Include boundaries; Whether to set each bound as closed or open. | ||
| 
     | 
||
| .. versionadded:: 1.4.0 | ||
| **kwargs | ||
| For compatibility. Has no effect on the result. | ||
| 
     | 
||
| 
          
            
          
           | 
    @@ -1143,6 +1183,7 @@ def bdate_range( | |
| normalize=normalize, | ||
| name=name, | ||
| closed=closed, | ||
| inclusive=inclusive, | ||
| **kwargs, | ||
| ) | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
  
    
      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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  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.
  
    
  
    
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.
versionadded 1.4.0