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

Bug when assigning timedelta64 to a series (or dataframe) with an indexer #14155

Closed
Talmaj opened this issue Sep 5, 2016 · 2 comments
Closed
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Timedelta Timedelta data type
Milestone

Comments

@Talmaj
Copy link

Talmaj commented Sep 5, 2016

Code Sample, a copy-pastable example if possible

In [2]: import pandas as pd

In [3]: import numpy as np

In [4]: s = pd.Series(10*[np.timedelta64(10, 'm')])

In [5]: s
Out[5]: 
0   00:10:00
1   00:10:00
2   00:10:00
3   00:10:00
4   00:10:00
5   00:10:00
6   00:10:00
7   00:10:00
8   00:10:00
9   00:10:00
dtype: timedelta64[ns]

In [6]: s.ix[[1,2,3]] = np.timedelta64(20, 'm')

In [7]: s
Out[7]: 
0          00:10:00
1   00:00:00.000000
2   00:00:00.000000
3   00:00:00.000000
4          00:10:00
5          00:10:00
6          00:10:00
7          00:10:00
8          00:10:00
9          00:10:00
dtype: timedelta64[ns]

Expected Output

In [7]: s
Out[7]: 
0          00:10:00
1          00:20:00
2          00:20:00
3          00:20:00
4          00:10:00
5          00:10:00
6          00:10:00
7          00:10:00
8          00:10:00
9          00:10:00
dtype: timedelta64[ns]

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.0.final.0
python-bits: 64
OS: Darwin
OS-release: 14.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8

pandas: 0.18.1
nose: None
pip: 8.1.2
setuptools: 18.2
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.0
statsmodels: None
xarray: None
IPython: 4.0.3
sphinx: 1.4.6
patsy: None
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: None
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.1
openpyxl: 2.3.3
xlrd: 0.9.4
xlwt: None
xlsxwriter: None
lxml: 3.5.0
bs4: 4.4.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.15
pymysql: 0.7.5.None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: None
@jreback
Copy link
Contributor

jreback commented Sep 5, 2016

the scalar is not getting wrapped in a Timedelta, which handles all of the conversions. you can do this as a work-around. This is also the fix for the bug. PR's are appreciated. here, should be like the section just below. (for timedelta)

In [11]: s.ix[[1,2,3]] = pd.Timedelta(np.timedelta64(20, 'm'))

In [12]: s
Out[12]: 
0   00:10:00
1   00:20:00
2   00:20:00
3   00:20:00
4   00:10:00
5   00:10:00
6   00:10:00
7   00:10:00
8   00:10:00
9   00:10:00
dtype: timedelta64[ns]

@jreback jreback added this to the Next Major Release milestone Sep 5, 2016
@jreback jreback added the Indexing Related to indexing on series/frames, not to indexes themselves label Sep 5, 2016
@rsmith54
Copy link

rsmith54 commented Sep 6, 2016

Hi,

I have submitted a pull request #14160 which fixes this issue. This would be my first contribution to pandas, so if there are any issues let me know. In particular, I looked a bit where to add a test (maybe here ? ), but I wasn't exactly sure how to test this change. Thanks !

Cheers,
Russell

@jreback jreback modified the milestones: 0.19.0, Next Major Release Sep 7, 2016
@jreback jreback closed this as completed in ff435ba Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Indexing Related to indexing on series/frames, not to indexes themselves Timedelta Timedelta data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants