We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
# Your code here >>> pd.Series([], index=pd.date_range(start="2018-01-01", periods=0), dtype=int).apply(lambda x: x) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/.../lib/python3.6/site-packages/pandas/core/series.py", line 2526, in apply index=self.index).__finalize__(self) File "/.../lib/python3.6/site-packages/pandas/core/series.py", line 264, in __init__ raise_cast_failure=True) File "/.../lib/python3.6/site-packages/pandas/core/series.py", line 3228, in _sanitize_array subarr = _try_cast(data, False) File "/.../lib/python3.6/site-packages/pandas/core/series.py", line 3163, in _try_cast subarr = np.array(subarr, dtype=dtype, copy=copy) ValueError: cannot convert float NaN to integer
For some reason, apply method doesn't work for empty series with datetime index and dtype int. Obviously, it should work.
apply
>>> pd.Series([], index=pd.date_range(start="2018-01-01", periods=0), dtype=int).apply(lambda x: x) Series([], Freq: D, dtype: int64)
pd.show_versions()
commit: None python: 3.6.5.final.0 python-bits: 64 OS: Linux OS-release: 4.14.42 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8
pandas: 0.22.0 pytest: None pip: None setuptools: 39.0.1 Cython: 0.28.1 numpy: 1.14.2 scipy: 1.0.1 pyarrow: None xarray: None IPython: None sphinx: None patsy: None dateutil: 2.6.1 pytz: 2018.3 blosc: None bottleneck: 1.2.1 tables: 3.4.2 numexpr: 2.6.4 feather: None matplotlib: None openpyxl: 2.5.2 xlrd: 0.9.4 xlwt: 1.3.0 xlsxwriter: None lxml: 4.2.1 bs4: 4.6.0 html5lib: 1.0.1 sqlalchemy: 1.2.6 pymysql: None psycopg2: None jinja2: None s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None
The text was updated successfully, but these errors were encountered:
Not sure how much this issue is related, but it might be: #21192
Sorry, something went wrong.
This has been fixed in the latest release.
In [14]: pd.__version__ Out[14]: u'0.23.0' In [15]: pd.Series([], index=pd.date_range(start="2018-01-01", periods=0), dtype=int).apply(lambda x: x) Out[15]: Series([], Freq: D, dtype: int64)
@jreback do we have this edge case tested?
Hi, I would like to write test case for this as part of PyCon India'19 dev sprint. @mroeschke Can you please elaborate on the edge test case.
We would just need a test seeing that the original issue was fixed. Namely that the example in #21245 (comment) gives the stated desired output
Successfully merging a pull request may close this issue.
Code Sample, a copy-pastable example if possible
Problem description
For some reason,
apply
method doesn't work for empty series with datetime index and dtype int. Obviously, it should work.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Linux
OS-release: 4.14.42
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.22.0
pytest: None
pip: None
setuptools: 39.0.1
Cython: 0.28.1
numpy: 1.14.2
scipy: 1.0.1
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2018.3
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.4
feather: None
matplotlib: None
openpyxl: 2.5.2
xlrd: 0.9.4
xlwt: 1.3.0
xlsxwriter: None
lxml: 4.2.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.6
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: