Skip to content
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

Snap drops name from datetimeindex #25575

Closed
danielwlogan opened this issue Mar 6, 2019 · 4 comments

Comments

@danielwlogan
Copy link

commented Mar 6, 2019

Code Sample, a copy-pastable example if possible

import pandas as pd

dti = pd.DatetimeIndex([], name='my_dti', freq='H')
print(dti.round('D'))  # Name is preserved
print(dti.snap('D'))  # Name is lost

Problem description

The DatetimeIndex.snap method loses the name of the DatetimeIndex which is a different behaviour than DatetimeIndex.round (or floor, ceil, etc.) that preserves the name of the DatetimeIndex.

Expected Output

DatetimeIndex([], dtype='datetime64[ns]', name='my_dti', freq='D')

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.7.final.0
python-bits: 64
OS: Linux
OS-release: 4.15.0-45-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_CA.UTF-8
LOCALE: en_CA.UTF-8

pandas: 0.24.1
pytest: 4.0.0
pip: 19.0.3
setuptools: 40.4.3
Cython: 0.29.6
numpy: 1.16.2
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.3.0
sphinx: None
patsy: 0.5.0
dateutil: 2.7.3
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 3.0.3
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.2.1
bs4: None
html5lib: 1.0.1
sqlalchemy: 1.2.18
pymysql: None
psycopg2: 2.7.7 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: 0.9.0
pandas_datareader: None
gcsfs: None

@mroeschke

This comment has been minimized.

Copy link
Member

commented Mar 6, 2019

Thanks for the report. There's actually a comment in the code that notes that this is missing (as well as tz). PR's welcome!

return DatetimeIndex._simple_new(snapped, freq=freq)
# TODO: what about self.name? tz? if so, use shallow_copy?

@danielwlogan

This comment has been minimized.

Copy link
Author

commented Mar 6, 2019

How does snap actually work?

pd.date_range(start='2019-1-1', end='2019-1-2', freq='10T').snap('H')

Doesn't return what I expect. Is this a bigger bug?

sighingnow added a commit to sighingnow/pandas that referenced this issue Mar 7, 2019

@sighingnow sighingnow referenced this issue Mar 7, 2019

Merged

BUG: Preserve name in DatetimeIndex.snap #25585

4 of 4 tasks complete
@heidek

This comment has been minimized.

Copy link

commented Mar 8, 2019

How does snap actually work?

pd.date_range(start='2019-1-1', end='2019-1-2', freq='10T').snap('H')

Doesn't return what I expect. Is this a bigger bug?

I'm not exactly sure how snap is supposed to work or what differentiates it from round. Don't think I've seen a single working example showing how snap is intended to be used. Does anyone know what it's supposed to do beyond the one sentence description in the docstring?

@danielwlogan

This comment has been minimized.

Copy link
Author

commented Mar 8, 2019

I have been poking around through trial and error. The best that I can come up with is that:

  1. It is for dates only (times seem to be unaffected)
  2. It seems to work when the frequencies are things like W-MON. Which means it just works on "Anchored Offsets"?

I came across snap when I was looking for a round/floor type method that can handle time changes. I still don't know if snap would work, but I know that it doesn't seem to do what I expect based on the little documentation I can find.

@jreback jreback added this to the 0.25.0 milestone Mar 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.