Skip to content

BUG: pd._libs.lib.is_iterator reports Timestamp as iterable on Cygwin #45158

Closed
@DWesl

Description

@DWesl

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 master branch of pandas.

Reproducible Example

>>> import pandas as pd
>>> stamp = pd.Timestamp("2010-01-03T07:23:48")
>>> pd._libs.lib.is_iterator(stamp)
True
>>> list(stamp)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Timestamp' object is not iterable
>>> pd.__version__
'1.3.4'
>>> import collections.abc
>>> isinstance(stamp, collections.abc.Iterator)
False
>>> next(stamp)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'Timestamp' object is not an iterator
$ for ver in 3.{6,7,8}; do 
>     python${ver} -c "import collections.abc, pandas as pd; stamp = pd.Timestamp('1987-06-05T04:32:10'); 
> print(pd.__version__, pd._libs.lib.is_iterator(stamp), isinstance(stamp, collections.abc.Iterator))"; 
> done
1.1.4 True False
1.3.4 True False
1.3.4 True False

Issue Description

I have noticed two functions in pandas that use the above pattern:

pandas.core.indexing._LocationIndexer.__getitem__(self, tuple)
pandas.core.indexing._LocIndexer._getitem_axis(self, tuple)

This is causing tests to fail as I try to build 1.3.5. Both the attempt shown above and the attempt with 1.3.5 are on Cygwin. The problem does not occur with pandas 1.0.5, 1.1.2, or 1.3.5 on Windows. All attempts were made with the CPython implementation.

Expected Behavior

I would expect either is_iterator to return False or list to succeed.

Installed Versions

>>> pd.show_versions()
/usr/lib/python3.8/site-packages/h5py/__init__.py:36: UserWarning: h5py is running against HDF5 1.10.8 when it was built against 1.10.7, this may cause problems
  _warn(("h5py is running against HDF5 {0} when it was built against {1}, "

INSTALLED VERSIONS
------------------
commit           : 945c9ed766a61c7d2c0a7cbb251b6edebf9cb7d5
python           : 3.8.12.final.0
python-bits      : 64
OS               : CYGWIN_NT-10.0-19043
OS-release       : 3.3.3-341.x86_64
Version          : 2021-12-03 16:35 UTC
machine          : x86_64
processor        :
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.3.4
numpy            : 1.21.4
pytz             : 2021.3
dateutil         : 2.8.2
pip              : 21.3.1
setuptools       : 59.6.0
Cython           : 0.29.25
pytest           : 6.2.5
hypothesis       : 6.31.3
sphinx           : 4.0.3
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : 4.7.1
html5lib         : 1.1
pymysql          : None
psycopg2         : None
jinja2           : 3.0.3
IPython          : 7.30.1
pandas_datareader: None
bs4              : 4.10.0
bottleneck       : 1.3.2
fsspec           : 2021.06.0
fastparquet      : None
gcsfs            : None
matplotlib       : 3.5.1
numexpr          : 2.8.0
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : 1.7.1
sqlalchemy       : 1.4.28
tables           : None
tabulate         : 0.8.7
xarray           : 0.18.2
xlrd             : None
xlwt             : None
numba            : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions