BUG: strftime format string validation is inconsistent between Timestamp
and DatetimeIndex
#48588
Closed
2 of 3 tasks
Labels
Bug
datetime.date
stdlib datetime.date support
Needs Triage
Issue that has not been reviewed by a pandas team member
Timestamp
pd.Timestamp and associated methods
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
On Windows, the validation performed on the format string is not the same between
Timestamp.strftime
andDatetimeIndex.strftime
. With the included reproducible example,DatetimeIndex.strftime
executes without error (although the correctness of the returned string is questionable):Whereas the
Timestamp
equivalent raises an error:I believe the format string in the above example is invalid due to the trailing
%
character (although I'm not positive since format codes are platform-specific to some degree), but regardless I'd expect consistent validation behavior betweenTimestamp.strftime
andDatetimeIndex.strftime
, all else equal.On Linux with this particular format string I get no difference in behavior between
Timestamp
andDatetimeIndex
, although I note that the returned string is different from on Windows:'2019-11-01 00:00%'
andIndex(['2019-11-01 00:00%'], dtype='object')
, respectively.Expected Behavior
For the same format string and underlying timestamp, I expected
Timestamp.strftime
andDatetimeIndex.strftime
to have equivalent format validation behavior, i.e. either both of them raise an error or neither does.Installed Versions
Details (Windows)
INSTALLED VERSIONS
commit : ca60aab
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252
pandas : 1.4.4
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
Details (Linux)
INSTALLED VERSIONS
commit : ca60aab
python : 3.10.4.final.0
python-bits : 64
OS : Linux
OS-release : 5.19.0-76051900-generic
Version : #202207312230
166078056622.04~9d60db1 SMP PREEMPT_DYNAMIC Thu Amachine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.4.4
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
markupsafe : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
The text was updated successfully, but these errors were encountered: