8000 REGR: fix bug in DatetimeIndex slicing with irregular or unsorted indices by CloseChoice · Pull Request #37023 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REGR: fix bug in DatetimeIndex slicing with irregular or unsorted indices #37023

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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f1d4a10
remove assert in core/generic.py and add test for datetimeindex slicing
CloseChoice Oct 10, 2020
cd1a136
fix formatting in test_generic
CloseChoice Oct 10, 2020
fe478c4
fix test and remove commented line
CloseChoice Oct 10, 2020
15a9185
updated tests according to PR comments
CloseChoice Oct 10, 2020
6caba47
slice with loc to prevent future warning
CloseChoice Oct 10, 2020
5703994
revert changes in io/formats/css.py
CloseChoice Oct 10, 2020
4a7ff03
run black on test_timeseries.py
CloseChoice Oct 10, 2020
25b229c
move tests to indexing/test_partial, add whatsnew entry
CloseChoice Oct 11, 2020
9bb10fe
reformat test_timeseries.py
CloseChoice Oct 11, 2020
9d82f83
Merge branch 'master' of https://github.com/pandas-dev/pandas into BU…
CloseChoice Oct 11, 2020
968fdf4
update whatsnew
CloseChoice Oct 11, 2020
89b0248
Merge branch 'master' into BUG-regression-datetimeindex-slicing
CloseChoice Oct 16, 2020
3710514
add suggestion from comment
CloseChoice Oct 16, 2020
237b085
use result and expected in tests
CloseChoice Oct 16, 2020
43a2a26
Merge branch 'master' of https://github.com/pandas-dev/pandas into BU…
CloseChoice Oct 20, 2020
632855b
Update doc/source/whatsnew/v1.1.4.rst
CloseChoice Oct 20, 2020
e79cdac
Merge branch 'master' of https://github.com/pandas-dev/pandas into BU…
CloseChoice Oct 21, 2020
e5f3615
Merge branch 'BUG-regression-datetimeindex-slicing' of github.com:Clo…
CloseChoice Oct 21, 2020
4261f02
Merge branch 'master' of https://github.com/pandas-dev/pandas into BU…
CloseChoice Oct 22, 2020
583003e
Merge remote-tracking branch 'upstream/master' into BUG-regression-da…
simonjayhawkins Oct 26, 2020
e246520
Update pandas/tests/indexing/test_partial.py
MarcoGorelli Oct 26, 2020
9cf919e
Update pandas/tests/indexing/test_partial.py
MarcoGorelli Oct 26, 2020
7f693dc
Update pandas/tests/indexing/test_partial.py
MarcoGorelli Oct 26, 2020
02ae223
Update pandas/tests/indexing/test_partial.py
MarcoGorelli Oct 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move tests to indexing/test_partial, add whatsnew entry
  • Loading branch information
CloseChoice committed Oct 11, 2020
commit 25b229c425765bec6e9203a30fade4ced199ff15
1 change: 1 addition & 0 deletions 8000 doc/source/whatsnew/v1.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Fixed regressions
- Fixed regression where attempting to mutate a :class:`DateOffset` object would no longer raise an ``AttributeError`` (:issue:`36940`)
- Fixed regression where :meth:`DataFrame.agg` would fail with :exc:`TypeError` when passed positional arguments to be passed on to the aggregation function (:issue:`36948`).
- Fixed regression in :class:`RollingGroupby` with ``sort=False`` not being respected (:issue:`36889`)
- Fixed regression where slicing :class:`DatetimeIndex` failed on irregular time series with `pd.NaT` or on unsorted indices (:issue:`36953` and :issue:`35509`)

.. ---------------------------------------------------------------------------

Expand Down
18 changes: 0 additions & 18 deletions pandas/tests/frame/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,3 @@ def test_datetime_assignment_with_NaT_and_diff_time_units(self):
)
tm.assert_frame_equal(result, expected)

def test_slice_irregular_datetime_index_with_nan(self):
# GH36953
index = pd.to_datetime(["2012-01-01", "2012-01-02", "2012-01-03", None])
df = pd.DataFrame(range(len(index)), index=index)
expected = pd.DataFrame(range(len(index[:3])), index=index[:3])
tm.assert_frame_equal(df["2012-01-01":"2012-01-04"], expected)

def test_slice_datetime_index(self):
# GH35509
df = pd.DataFrame(
{"col1": ["a", "b", "c"], "col2": [1, 2, 3]},
index=pd.to_datetime(["2020-08-01", "2020-07-02", "2020-08-05"]),
)
expected = pd.DataFrame(
{"col1": ["a", "c"], "col2": [1, 3]},
index=pd.to_datetime(["2020-08-01", "2020-08-05"]),
)
tm.assert_frame_equal(df.loc["2020-08"], expected)
19 changes: 19 additions & 0 deletions pandas/tests/indexing/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,22 @@ def test_index_name_empty(self):
{"series": [1.23] * 4}, index=pd.RangeIndex(4, name="series_index")
)
tm.assert_frame_equal(df, expected)

def test_slice_irregular_datetime_index_with_nan(self):
# GH36953
index = pd.to_datetime(["2012-01-01", "2012-01-02", "2012-01-03", None])
df = pd.DataFrame(range(len(index)), index=index)
expected = pd.DataFrame(range(len(index[:3])), index=index[:3])
tm.assert_frame_equal(df["2012-01-01":"2012-01-04"], expected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you define result = df["2012-01-01":"2012-01-04"] above?


def test_slice_datetime_index(self):
# GH35509
df = pd.DataFrame(
{"col1": ["a", "b", "c"], "col2": [1, 2, 3]},
index=pd.to_datetime(["2020-08-01", "2020-07-02", "2020-08-05"]),
)
expected = pd.DataFrame(
{"col1": ["a", "c"], "col2": [1, 3]},
index=pd.to_datetime(["2020-08-01", "2020-08-05"]),
)
tm.assert_frame_equal(df.loc["2020-08"], expected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you define result = df["2020-08"] above?

0