Skip to content

Timestamp AttributeError #11630

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
ktownv opened this issue Nov 17, 2015 · 10 comments
Closed

Timestamp AttributeError #11630

ktownv opened this issue Nov 17, 2015 · 10 comments
Labels
Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@ktownv
Copy link

ktownv commented Nov 17, 2015

pandas 0.17.0, python 2.7.10:

import pandas as pd
p = pd.Timestamp(2015, 11, 12)
p
Traceback (most recent call last):
File "", line 1, in
File "pandas\tslib.pyx", line 339, in pandas.tslib.Timestamp.repr (pandas\tslib.c:9660)
AttributeError: 'int' object has no attribute 'freqstr'

@jreback
Copy link
Contributor

jreback commented Nov 17, 2015

You are not calling correct.y

In [40]: pd.Timestamp?
Type:        type
String form: <class 'pandas.tslib.Timestamp'>
File:        c:\miniconda\envs\neat\lib\site-packages\pandas\tslib.pyd
Docstring:
TimeStamp is the pandas equivalent of python's Datetime
and is interchangable with it in most cases. It's the type used
for the entries that make up a DatetimeIndex, and other timeseries
oriented data structures in pandas.

Parameters
----------
ts_input : datetime-like, str, int, float
    Value to be converted to Timestamp
offset : str, DateOffset
    Offset which Timestamp will have
tz : string, pytz.timezone, dateutil.tz.tzfile or None
    Time zone for time which Timestamp will have.
unit : string
    numpy unit used for conversion, if ts_input is int or float

@ktownv
Copy link
Author

ktownv commented Nov 17, 2015

then it should fail at the creation of the object, not leave me with something in an inconsistent state that doesn't play nicely in the interpreter.

for example

str(p)
'1970-01-01 00:00:00.000002015+00:00'

works.

calls to repr should never raise an exception.

@jreback
Copy link
Contributor

jreback commented Nov 17, 2015

actually it should raise if the offset is not None or a string.

code is here

pull-requests to fix are welcome.

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Nov 17, 2015
@jreback jreback added this to the Next Major Release milestone Nov 17, 2015
@jreback jreback reopened this Nov 17, 2015
@IamGianluca
Copy link

I can work on this.

@IamGianluca
Copy link

I'm having some troubles solving this bug. I'm not familiar with cython and its workflow. Should I just fix the code in the .pyx file and then rebuild the C dependencies, right? Because when I try to run python setup.py build_ext --inplace I get lots of warnings and can't complete building the Timedelta C extension.

I've created a Question in StackOverflow with all the details.

@jreback
Copy link
Contributor

jreback commented Nov 29, 2015

yes, you need to fix in the .pyx and then run setup. if their are compilation errors then it won't import, warnings are ok.

SO in general is not helpful with this kind of thing.

@IamGianluca
Copy link

I don't understand what's wrong here. This is the log of the build. There are lots of warnings but nothing that help me identify the route cause of the issue. The build also doesn't fail, however when I try to run the nosetests immediately after I get this error message:

grossi-ml:pandas-iamgianluca grossi$ nosetests pandas/
E
======================================================================
ERROR: Failure: ImportError (C extension: Timedelta not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/grossi/anaconda/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/Users/grossi/anaconda/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Users/grossi/anaconda/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/Users/grossi/PycharmProjects/pandas-iamgianluca/pandas/__init__.py", line 13, in <module>
    "extensions first.".format(module))
ImportError: C extension: Timedelta not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)

Interestingly if I remove my changes I can build and then run nosetests without problems.

My code however seems fine to me. I've just added an else statement and imported the DateOffset class:

        if util.is_string_object(offset):
            from pandas.tseries.frequencies import to_offset
            offset = to_offset(offset)
        else:
            from pandas.tseries.offsets import DateOffset
            if not isinstance(offset, DateOffset):
                raise ValueError

@jreback
Copy link
Contributor

jreback commented Dec 2, 2015

trying putting a debugging statement right before the import then you can see where its called. you have a circular import is the issue.

@gliptak
Copy link
Contributor

gliptak commented May 8, 2016

Changes to isoformat in current HEAD corrected this.

File "pandas/tslib.pyx", line 567, in pandas.tslib.Timestamp.isoformat (pandas/tslib.c:13019)

@gliptak
Copy link
Contributor

gliptak commented May 9, 2016

No longer sure that this works as expected, I will pull the change by @IamGianluca from above ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants