Skip to content

pd.Timestamp.isoformat does not implement keyword timespec #26131

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
MaximeWeyl opened this issue Apr 18, 2019 · 15 comments · Fixed by #44397
Closed

pd.Timestamp.isoformat does not implement keyword timespec #26131

MaximeWeyl opened this issue Apr 18, 2019 · 15 comments · Fixed by #44397
Assignees
Labels
Datetime Datetime data dtype Enhancement
Milestone

Comments

@MaximeWeyl
Copy link

Code Sample

[IN]

import pandas as pd
now = pd.Timestamp.utcnow()
help(now.isoformat)

[OUT]
Help on method isoformat in module pandas._libs.tslibs.timestamps:

isoformat(sep='T') method of pandas._libs.tslibs.timestamps.Timestamp instance
    [sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].
    sep is used to separate the year from the time, and defaults to 'T'.
    timespec specifies what components of the time to include (allowed values are 'auto', 'hours', 'minutes', 'seconds', 'milliseconds', and 'microseconds').

[IN]

now.isoformat(timespec="seconds")

[OUT]
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-8-3626478eeb62> in <module>
----> 1 now.isoformat(timespec="seconds")


pandas\_libs\tslibs\timestamps.pyx in pandas._libs.tslibs.timestamps.Timestamp.isoformat()


TypeError: isoformat() got an unexpected keyword argument 'timespec'

[IN]

now.to_pydatetime().isoformat(timespec="seconds")

[OUT]
'2019-04-18T07:38:50+00:00'

Problem description

The help method has given me the feeling that I can use timespec just like I can with standard datetime objects (since python 3.6).

Expected Output

We could mimic standard datetime.isoformat behavior, or at least remove this false information from the help message.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: None.None

pandas: 0.24.2
pytest: 4.4.1
pip: 19.0.3
setuptools: 41.0.0
Cython: None
numpy: 1.16.2
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.4.0
sphinx: 2.0.1
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2019.1
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.3.3
bs4: 4.7.1
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None

@WillAyd
Copy link
Member

WillAyd commented Apr 18, 2019

@mroeschke @jbrockmendel

@mroeschke
Copy link
Member

isoformat is one function that Timestamp doesn't just directly inherit. I don't see why the timespec keyword argument can't be incorporated in as well.

One thing to note is that if we mirror timespec from datetime.datetime, our implementation also should handle 'nanoseconds' as an argument

@mroeschke mroeschke added the Datetime Datetime data dtype label Apr 18, 2019
@jbrockmendel
Copy link
Member

Might be helpful to have a test checking compatibility of all the signatures between datetime vs timestamp.

@MaximeWeyl
Copy link
Author

I have another remark : the help message is very different when looking at the Timestamp class or at the instance :

import pandas as pd
help(pd.Timestamp.isoformat)
Help on cython_function_or_method in module pandas._libs.tslibs.timestamps:

isoformat(self, sep='T')
help(pd.Timestamp(2019).isoformat)
Help on method isoformat in module pandas._libs.tslibs.timestamps:

isoformat(sep='T') method of pandas._libs.tslibs.timestamps.Timestamp instance
    [sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].
    sep is used to separate the year from the time, and defaults to 'T'.
    timespec specifies what components of the time to include (allowed values are 'auto', 'hours', 'minutes', 'seconds', 'milliseconds', and 'microseconds').

@77QingLiu
Copy link

update this apli, please

@jreback
Copy link
Contributor

jreback commented Nov 4, 2019

update this apli, please

@77QingLiu
you are welcome to submit a PR to patch this

@boringow
Copy link

boringow commented Feb 2, 2021

Hello, I am still having this same issue.

@jreback
Copy link
Contributor

jreback commented Feb 2, 2021

@boringow this is an open issue
you are welcome to submit a PR
there is an open PR but it is stale

@boringow
Copy link

boringow commented Feb 3, 2021

How can I do a PR in this issue? can someone assign it to me please?

@boringow
Copy link

boringow commented Feb 3, 2021

@phofl Hi again and sorry to bother, I need to be a triage member to do PR. How can I become one?

@phofl
Copy link
Member

phofl commented Feb 3, 2021

Everyone can open a Pull Request. I think you did one a few days back?

@boringow
Copy link

boringow commented Feb 3, 2021

@phofl sorry, I could no do it from the mobile. I do it right now. Can you asign this task to me so I deal with it? Although I do not know git/github I have experiences with pandas and developing and I think I can solve it.

@phofl
Copy link
Member

phofl commented Feb 3, 2021

Assigned it to you. You can self assign through posting take in the future

@boringow
Copy link

boringow commented Feb 6, 2021

Okay, I need some help in here as I am lacking some knowledge.
I did the same but simple quick code to start with the issue:

import pandas as pd
import pdb

now=pd.Timestamp.utcnow()

print(now)
pdb.set_trace()
a=now.isoformat(sep="seconds")
print(a)

To start, the keyword ' timespec ' is not defined, only the keyword 'sep' is defined, as the documentation indicates, but it is also not working.
For some reason, the debugging does not go into the: pandas._libs.tslibs.timestamps Module,
If I try to debug the error, it says there is an error on the python codecs.

C:\user\python\python38-32\lib\codecs.py(309)init()
-> def init(self, errors='strict'):

TypeError: isoformat() argument 1 must be a unicode character, not str.

If we see the .isoformat method (

def isoformat(self, sep: str = "T") -> str:
)
We will always get the base, as nanoseconds from a timestamp.now() will always be zero.
How does pandas handle nanoseconds but datetime does not? I think the error is in there, But I need help.

@simonjayhawkins
Copy link
Member

The PR for issue #38550 was closed as stale. review comments there could be useful. contributions welcome

@simonjayhawkins simonjayhawkins modified the milestones: 1.3, Contributions Welcome Jun 11, 2021
@jreback jreback modified the milestones: Contributions Welcome, 1.4 Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment