-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: Series.map
passes DatetimeIndex
as first argument on some series
#44392
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
Comments
Hmm I don't see an error on master and don't really follow how
|
def mapping_func(ts):
print(ts) ts_list = [
datetime(2021, randint(1, 12), randint(1, 28))
for _ in range(5)
]
df01 = pd.DataFrame(ts_list, columns=["timestamps"])
df01["timestamps"].map(mapping_func) Output:
ts_list_02 = [
'2020-09-01T15:47:33.953000+00:00',
'2020-09-02T16:57:16.547000+00:00',
'2020-09-02T16:57:16.887000+00:00',
'2020-09-02T16:57:12.377000+00:00',
'2020-09-02T16:57:12.667000+00:00',
]
df02 = pd.DataFrame(ts_list_02, columns=["timestamps"])
df02["timestamps"] = pd.to_datetime(df02["timestamps"])
df02["timestamps"].map(mapping_func) Output:
As you see in the second example, before running the actual five iterations, |
I also reproduced it in this notebook in case it helps. |
I see. Thanks, the |
Confirm that this issue is present on the master branch.
I'll try to take this problem. I'll start by creating a test that will show this. |
I'm trying to catch the exception with this test:
The test showed nothing. In this case, the function returns nothing. The error is only visible when using print () |
Very weird, because I can't reproduce it either when trying in the notebook I sent above; but I can reproduce it locally on my machine with |
Maybe related to #43940? |
Absolutely, thanks for pointing out! To sum it up:
def mapping_func(ts):
print(ts)
assert isinstance(ts, pd.Timestamp)
ts_list_02 = [
'2020-09-01T15:47:33.953000+00:00',
'2020-09-02T16:57:16.547000+00:00',
'2020-09-02T16:57:16.887000+00:00',
'2020-09-02T16:57:12.377000+00:00',
'2020-09-02T16:57:12.667000+00:00',
]
df02 = pd.DataFrame(ts_list_02, columns=["timestamps"])
df02["timestamps"] = pd.to_datetime(df02["timestamps"])
df02["timestamps"].map(mapping_func) Output of debug:
and raises an error from the Output of running the script from console:
with no error raised. |
Uh oh!
There was an error while loading. Please reload this page.
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
Issue Description
I am having a weird issued when using
Series.map(arg=fn)
on a series containingTimestamp
s:fn
is called by map, the argument is aDatetimeIndex
containing all timestamps in the series. Further calls pass every individual member of the series tofn
as expected.fn
as expected.I was able to reproduce it by:
datetime
s instances (df01
in the example - works as expected).Timestamp
usingpd.to_datetime
(df02
in the example - doesn't work as expected aka. passes a fullDatetimeIndex
the first time it callsfn
).Expected Behavior
Works as expected, the
ts
parameter ofmapping_func
always being aTimestamp
instance.Should not raise an error but actually does, since the first time
mapping_func
is called, thets
parameter is passed aDatetimeIndex
.Installed Versions
INSTALLED VERSIONS
commit : 945c9ed
python : 3.7.9.final.0
python-bits : 64
OS : Darwin
OS-release : 20.5.0
Version : Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : None.UTF-8
pandas : 1.3.4
numpy : 1.21.4
pytz : 2021.3
dateutil : 2.8.2
pip : 21.1.3
setuptools : 57.4.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.2
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.9.1 (dt dec pq3 ext lo64)
jinja2 : 3.0.3
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.11.0
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.9
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : 1.4.26
tables : None
tabulate : 0.8.9
xarray : None
xlrd : None
xlwt : None
numba : None
The text was updated successfully, but these errors were encountered: