Skip to content

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

Closed

Conversation

cpaulik
Copy link

@cpaulik cpaulik commented Apr 20, 2017

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.

@cpaulik cpaulik force-pushed the fix-length-1-loc-slice-GH16071 branch from 48ffae7 to 2ea12bc Compare April 20, 2017 15:20
Copy link
Contributor

@TomAugspurger TomAugspurger left a 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.

df_sliced_dt = df.loc[datetime(2016, 10, 1):]
tm.assert_frame_equal(df, df_sliced_dt)

df = pd.DataFrame(columns=['1'],
Copy link
Contributor

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).



def test_loc_datetime_length_one():
"""
Copy link
Contributor

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

Test if DataFrame with length one is properly sliced
by .loc.
"""
from datetime import datetime
Copy link
Contributor

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)

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):]
Copy link
Contributor

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)

@@ -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')
Copy link
Contributor

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

@@ -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)


Copy link
Contributor

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

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Datetime Datetime data dtype labels Apr 20, 2017
@cpaulik cpaulik force-pushed the fix-length-1-loc-slice-GH16071 branch from 2ea12bc to 527a5c0 Compare April 21, 2017 09:28
@codecov
Copy link

codecov bot commented Apr 21, 2017

Codecov Report

Merging #16072 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16072   +/-   ##
=======================================
  Coverage   90.82%   90.82%           
=======================================
  Files         159      159           
  Lines       50791    50791           
=======================================
  Hits        46132    46132           
  Misses       4659     4659
Flag Coverage Δ
#multiple 88.6% <100%> (ø) ⬆️
#single 40.36% <0%> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/datetimes.py 95.43% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ff00b55...527a5c0. Read the comment docs.

@cpaulik
Copy link
Author

cpaulik commented Apr 21, 2017

Thank you for the feedback. I made the requested changes.

@codecov
Copy link

codecov bot commented Apr 21, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@8c7b973). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #16072   +/-   ##
=========================================
  Coverage          ?   90.85%           
=========================================
  Files             ?      159           
  Lines             ?    50791           
  Branches          ?        0           
=========================================
  Hits              ?    46144           
  Misses            ?     4647           
  Partials          ?        0
Flag Coverage Δ
#multiple 88.63% <100%> (?)
#single 40.36% <0%> (?)
Impacted Files Coverage Δ
pandas/core/indexes/datetimes.py 95.43% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c7b973...9154732. Read the comment docs.

@cpaulik cpaulik force-pushed the fix-length-1-loc-slice-GH16071 branch from 527a5c0 to 9154732 Compare April 21, 2017 10:14
@jreback jreback added this to the 0.20.0 milestone Apr 21, 2017
@jreback jreback closed this in f7bce69 Apr 21, 2017
pcluo pushed a commit to pcluo/pandas that referenced this pull request May 22, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.loc slice with datetime string with DataFrame of length 1 gives an empty DataFrame
3 participants