ENH: consistency of input args for boundaries (pd.date_range)#43504
ENH: consistency of input args for boundaries (pd.date_range)#43504attack68 merged 10 commits intopandas-dev:masterfrom
Conversation
pandas/core/arrays/datetimelike.py
Outdated
| return periods | ||
|
|
||
|
|
||
| def validate_inclusiveness(inclusive): |
There was a problem hiding this comment.
maybe just call this validate_inclusive?
There was a problem hiding this comment.
couple of things. I would like to move this new routine & validate_entpoint to pandas/core/indexers/utils.py i think.
Also need to slightly refactor .between_time (which was just merged) to use the same.
Might be best to do these as a pre-cursor PR to this one.
There was a problem hiding this comment.
might also look at other merged prs from underlying issue that may be able to use this validator,
pandas/core/arrays/datetimelike.py
Outdated
| return periods | ||
|
|
||
|
|
||
| def validate_inclusiveness(inclusive): |
There was a problem hiding this comment.
couple of things. I would like to move this new routine & validate_entpoint to pandas/core/indexers/utils.py i think.
Also need to slightly refactor .between_time (which was just merged) to use the same.
Might be best to do these as a pre-cursor PR to this one.
| closed = date_range(begin, end, closed=None, freq=freq) | ||
| left = date_range(begin, end, closed="left", freq=freq) | ||
| right = date_range(begin, end, closed="right", freq=freq) | ||
| both = date_range(begin, end, inclusive="both", freq=freq) |
There was a problem hiding this comment.
can you parameterize this test instead, using the inclusive_endpoints_fixture fixtures (its in pandas/tests/frameso likely need to move topandas/conftest.py`
There was a problem hiding this comment.
yea makes sense, will do that
| closed = date_range(begin, end, closed=None, freq=freq) | ||
| left = date_range(begin, end, closed="left", freq=freq) | ||
| right = date_range(begin, end, closed="right", freq=freq) | ||
| both = date_range(begin, end, inclusive="both", freq=freq) |
| closed = date_range(begin, end, closed=None, freq=freq, tz="US/Eastern") | ||
| left = date_range(begin, end, closed="left", freq=freq, tz="US/Eastern") | ||
| right = date_range(begin, end, closed="right", freq=freq, tz="US/Eastern") | ||
| both = date_range(begin, end, inclusive="both", freq=freq, tz="US/Eastern") |
|
|
||
| @pytest.mark.parametrize("closed", ["right", "left", None]) | ||
| def test_range_closed_boundary(self, closed): | ||
| @pytest.mark.parametrize("inclusive", ["right", "left", "both", "neither"]) |
|
is this also closing #43394 ? e.g. a bug fix, if so this needs a separate note |
What do you mean by separate note by the way? |
|
go ahead and rebase this |
d84b4ae to
ff9b329
Compare
ff9b329 to
203733e
Compare
pandas/core/arrays/datetimes.py
Outdated
| # and removing would leave index empty | ||
| to_remove_any = not ( | ||
| (left_inclusive or right_inclusive) | ||
| and len(index) == 1 |
There was a problem hiding this comment.
shouldn't this be len(index) ?
There was a problem hiding this comment.
mm yeah, changed that and changed the tests in test_date_range
pandas/conftest.py
Outdated
| return request.param | ||
|
|
||
|
|
||
| @pytest.fixture(params=["both", "neither", "left", "right"]) |
There was a problem hiding this comment.
can you put next to this one and add a doc-string that is indicative
@pytest.fixture(params=["left", "right", "both", "neither"])
def closed(request):
"""
Fixture for trying all interval closed parameters.
"""
return request.param
jreback
left a comment
There was a problem hiding this comment.
looking good a few comments
| Argument `closed` have 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. |
| left_match = begin == both_range[0] | ||
| right_match = end == both_range[-1] | ||
|
|
||
| if inclusive_endpoints_fixture == "left" and right_match: |
There was a problem hiding this comment.
consider making this a function and share among these tests
There was a problem hiding this comment.
I defined the function on the top of the test_date_range.py file, does it belong elsewhere?
| right_match = endtz == both_range[-1] | ||
|
|
||
| if inclusive_endpoints_fixture == "left" and right_match: | ||
| expected_range = both_range[:-1] |
There was a problem hiding this comment.
same (so we don't repeat ourselves)
pandas/core/arrays/datetimes.py
Outdated
| (left_inclusive or right_inclusive) | ||
| and len(index) | ||
| and start == index[0] | ||
| and start == end |
There was a problem hiding this comment.
when is start != index[0]?
when is len(index) == 0 i.e. when will len(index) resolve as False?
when is start == end?
Do any of these cases imply the others?
pandas/core/arrays/datetimes.py
Outdated
| ) | ||
|
|
||
| if to_remove_any: | ||
| if (not left_inclusive) and len(index) and index[0] == start: |
There was a problem hiding this comment.
you are reusing the same logic tests deriving to_remove_any. I haven't come up with a better way but instinctively this feels a complicated logic path. Have you tried refactoring to a simpler setup?
There was a problem hiding this comment.
I refactored the logic a little and I am not sure if it is any better though
| 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.
its possible we would want to share this (across functoions), but ok here
|
https://github.com/pandas-dev/pandas/pull/43504/checks?check_run_id=3612446736 couple of tests that need addressing (you can either assert the future warning or just change closed -> inclusive in the test) |
attack68
left a comment
There was a problem hiding this comment.
lgtm pending green tests and some grammar corrections.
pandas/core/indexes/datetimes.py
Outdated
| the 'left', 'right', or both sides (None, the default). | ||
|
|
||
| .. deprecated:: 1.4.0 | ||
| Argument `closed` have been deprecated to standardize boundary inputs. |
pandas/core/indexes/datetimes.py
Outdated
| the 'left', 'right', or both sides (None). | ||
|
|
||
| .. deprecated:: 1.4.0 | ||
| Argument `closed` have been deprecated to standardize boundary inputs. |
|
some comments & can you merge master. ping on green. |
|
thanks @zyc09 |
…-dev#43504) Co-authored-by: JHM Darbyshire <24256554+attack68@users.noreply.github.com>
closes #43394
xref #40245