Skip to content

ValueError: cannot set a Timestamp with a non-timestamp #17995

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
jaradc opened this issue Oct 27, 2017 · 2 comments
Closed

ValueError: cannot set a Timestamp with a non-timestamp #17995

jaradc opened this issue Oct 27, 2017 · 2 comments
Labels
Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@jaradc
Copy link

jaradc commented Oct 27, 2017

Code Sample, a copy-pastable example if possible

from io import StringIO
df = pd.read_csv(StringIO('''Date,A\n8/23/2017,a\n8/22/2017,b\n8/24/2017,c'''), parse_dates=['Date'])
print(df)
print(type(pd.datetime(2017, 8, 22).date()))
print(type(df['Date'][1]))
df_sub = df[df['Date'] == pd.datetime(2017, 8, 22).date()]

Error returned

Traceback (most recent call last):
  File "<pyshell#72>", line 1, in <module>
    df_sub = df[df['Date'] == pd.datetime(2017, 8, 22).date()]
  File "C:\Python35\lib\site-packages\pandas\core\ops.py", line 877, in wrapper
    res = na_op(values, other)
  File "C:\Python35\lib\site-packages\pandas\core\ops.py", line 806, in na_op
    y = libindex.convert_scalar(x, _values_from_object(y))
  File "pandas\_libs\index.pyx", line 494, in pandas._libs.index.convert_scalar
  File "pandas\_libs\index.pyx", line 509, in pandas._libs.index.convert_scalar
ValueError: cannot set a Timestamp with a non-timestamp

Problem description

I just upgraded to pandas version '0.21.0rc1'. The df_sub line above used to work in a prior version. Should a Timestamp and a datetime.date be comparable like it used to in a previous version? Not a huge issue for me but my intent is to just report it in-case it requires attention.

Expected Output

        Date  A
1 2017-08-22  b

Helpful Links

May be a similar or related issue: #17965
convert_scalar location: https://github.com/pandas-dev/pandas/blob/master/pandas/_libs/index.pyx#L494

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]
INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Windows
OS-release: 7
machine: AMD64
processor: Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: English_United States.1252

pandas: 0.21.0rc1
pytest: None
pip: 9.0.1
setuptools: 20.10.1
Cython: 0.25.2
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 5.2.2
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.2
feather: None
matplotlib: 2.0.0rc2
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: 0.9.6
lxml: None
bs4: 4.5.3
html5lib: 0.9999999
sqlalchemy: 1.1.11
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jreback
Copy link
Contributor

jreback commented Oct 27, 2017

closing as duplicate of #17965

@jreback jreback closed this as completed Oct 27, 2017
@jreback jreback added Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves Datetime Datetime data dtype labels Oct 27, 2017
@jreback jreback added this to the No action milestone Oct 27, 2017
@liuli1735
Copy link

`temp = []
dates = data['TradingDay'].unique()
for date in dates:
print(date)
raw_data = data.loc[data['TradingDay'] == date].copy()

ValueError: cannot set a Timestamp with a non-timestamp`

I get the same error, i just upgrade my Anaconda yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Duplicate Report Duplicate issue or pull request Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

3 participants