-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Fix length 1 .loc slicing with datetime string GH16071 #16072
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
Conversation
48ffae7
to
2ea12bc
Compare
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 think since you aren't using any of the advanced pytest features like fixtures, it'd be better to include this test with other similar ones on the class.
pandas/tests/indexing/test_loc.py
Outdated
df_sliced_dt = df.loc[datetime(2016, 10, 1):] | ||
tm.assert_frame_equal(df, df_sliced_dt) | ||
|
||
df = pd.DataFrame(columns=['1'], |
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.
This is the same df
right? Shouldn't need to re-create it (unless I'm missing something).
pandas/tests/indexing/test_loc.py
Outdated
|
||
|
||
def test_loc_datetime_length_one(): | ||
""" |
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.
You can replace this docstring with the github issue number
pandas/tests/indexing/test_loc.py
Outdated
Test if DataFrame with length one is properly sliced | ||
by .loc. | ||
""" | ||
from datetime import datetime |
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.
datetime should already be imported (if not add at the very top)
pandas/tests/indexing/test_loc.py
Outdated
df = pd.DataFrame(columns=['1'], | ||
index=pd.date_range('2016-10-01T00:00:00', | ||
'2016-10-01T23:59:59')) | ||
df_sliced_dt = df.loc[datetime(2016, 10, 1):] |
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.
result = ....
tm.assert_frame_equal(result, df)
doc/source/whatsnew/v0.20.0.txt
Outdated
@@ -557,6 +557,7 @@ Other Enhancements | |||
- The ``display.show_dimensions`` option can now also be used to specify | |||
whether the length of a ``Series`` should be shown in its repr (:issue:`7117`). | |||
- ``parallel_coordinates()`` has gained a ``sort_labels`` keyword arg that sorts class labels and the colours assigned to them (:issue:`15908`) | |||
- ``loc`` indexer with datetime strings now works correctly for length 1 DataFrames and is consistent with the behaviour of using a ``datetime.datetime`` object (:issue:`16071') |
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.
move to Bug / Conversion section
just say: Bug in indexing with partial string indexing with a len-1
DataFrame
pandas/tests/indexing/test_loc.py
Outdated
@@ -628,3 +628,22 @@ def test_loc_empty_list_indexer_is_ok(self): | |||
tm.assert_frame_equal(df.loc[[]], df.iloc[:0, :], | |||
check_index_type=True, | |||
check_column_type=True) | |||
|
|||
|
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.
move this test to : pandas/tests/indexes/datetimes/test_partial_slcing.py
2ea12bc
to
527a5c0
Compare
Codecov Report
@@ Coverage Diff @@
## master #16072 +/- ##
=======================================
Coverage 90.82% 90.82%
=======================================
Files 159 159
Lines 50791 50791
=======================================
Hits 46132 46132
Misses 4659 4659
Continue to review full report at Codecov.
|
Thank you for the feedback. I made the requested changes. |
Codecov Report
@@ Coverage Diff @@
## master #16072 +/- ##
=========================================
Coverage ? 90.85%
=========================================
Files ? 159
Lines ? 50791
Branches ? 0
=========================================
Hits ? 46144
Misses ? 4647
Partials ? 0
Continue to review full report at Codecov.
|
527a5c0
to
9154732
Compare
closes pandas-dev#16071 Author: Christoph Paulik <christoph.paulik@geo.tuwien.ac.at> Closes pandas-dev#16072 from cpaulik/fix-length-1-loc-slice-GH16071 and squashes the following commits: 9154732 [Christoph Paulik] BUG: Fix length 1 .loc slicing with datetime string GH16071
I've written the test in pytest style since I read that you are moving to this style. If I misunderstood I can add the test to the class.
git diff upstream/master --name-only -- '*.py' | flake8 --diff