BUG: TypeError: 'generator' object is not callable when using pandas' date_range

This issue has been created since 2022-11-18.

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

time_array = pd.date_range(start='2020-6-1 00:00:00', end='2021-10-31 00:00:00', freq='H')

Issue Description

I'm using pandas' date_range to generate datetime arrays:

time_array = pd.date_range(start='2020-6-1 00:00:00', end='2021-10-31 00:00:00', freq='H')

And when I start to debug my code, my IDE tells me this error:

past_predict_single.py::test_gen_line_model FAILED                       
past_predict_single.py:83 (test_gen_line_model)
def test_gen_line_model():
        back_hours = 72  
>       time_array = pd.date_range(start='2020-6-1 00:00:00', end='2021-10-31 00:00:00', freq='H')
E       TypeError: 'generator' object is not callable

But when I run my code, this error diappears.

And another interesting thing: after the error appeared on the 1st computer, I chose the 2nd computer to debug my code, but after running my code for several times, the 2nd computer also appeared this problem.

Expected Behavior

Solve the problem

Installed Versions

commit : 91111fd

python : 3.10.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Chinese (Simplified)_China.936

pandas : 1.5.1
numpy : 1.23.4
pytz : 2022.6
dateutil : 2.8.2
setuptools : 65.5.0
pip : 22.3
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : 2022.10.0
gcsfs : None
matplotlib : 3.5.3
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : 2022.10.0
xlrd : None
xlwt : None
zstandard : None
tzdata : None

vamsi-verma-s wrote this answer on 2022-11-18

Hi @forestbat, i'm unable to replicate this. The error may be coming from a different part of your code. can you provide full stack trace.

forestbat wrote this answer on 2022-11-19

@vamsi-verma-s

2 = {traceback} <traceback object at 0x0000014656CD2900>
 tb_frame = {frame} test_gen_line_model [past_predict_single.py:86]  id:1401666378688
  stack = {list: 36} ['frame: test_gen_line_model [past_predict_single.py:86]  id:1401666378688', 'frame: pytest_pyfunc_call [python.py:195]  id:1401735341024', 'frame: _multicall [_callers.py:39]  id:1401664147920', 'frame: _hookexec [_manager.py:80]  id:1401735378128', 'frame: __call__ [_hooks.py:265]  id:1401735340544', 'frame: runtest [python.py:1789]  id:1401735388128', 'frame: pytest_runtest_call [runner.py:167]  id:1401735340064', 'frame: _multicall [_callers.py:39]  id:1401664144800', 'frame: _hookexec [_manager.py:80]  id:1401735376736', 'frame: __call__ [_hooks.py:265]  id:1401735339584', 'frame: <lambda> [runner.py:260]  id:1401735480224', 'frame: from_call [runner.py:339]  id:1401606849040', 'frame: call_runtest_hook [runner.py:259]  id:1401735337184', 'frame: call_and_report [runner.py:220]  id:1401735336704', 'frame: runtestprotocol [runner.py:131]  id:1401712033536', 'frame: pytest_runtest_protocol [runner.py:112]  id:1401735262080', 'frame: _multicall [_callers.py:39]  id:1401664137936', 'f...
   00 = {str} 'frame: test_gen_line_model [past_predict_single.py:86]  id:1401666378688'
   01 = {str} 'frame: pytest_pyfunc_call [python.py:195]  id:1401735341024'
   02 = {str} 'frame: _multicall [_callers.py:39]  id:1401664147920'
   03 = {str} 'frame: _hookexec [_manager.py:80]  id:1401735378128'
   04 = {str} 'frame: __call__ [_hooks.py:265]  id:1401735340544'
   05 = {str} 'frame: runtest [python.py:1789]  id:1401735388128'
   06 = {str} 'frame: pytest_runtest_call [runner.py:167]  id:1401735340064'
   07 = {str} 'frame: _multicall [_callers.py:39]  id:1401664144800'
   08 = {str} 'frame: _hookexec [_manager.py:80]  id:1401735376736'
   09 = {str} 'frame: __call__ [_hooks.py:265]  id:1401735339584'
   10 = {str} 'frame: <lambda> [runner.py:260]  id:1401735480224'
   11 = {str} 'frame: from_call [runner.py:339]  id:1401606849040'
   12 = {str} 'frame: call_runtest_hook [runner.py:259]  id:1401735337184'
   13 = {str} 'frame: call_and_report [runner.py:220]  id:1401735336704'
   14 = {str} 'frame: runtestprotocol [runner.py:131]  id:1401712033536'
   15 = {str} 'frame: pytest_runtest_protocol [runner.py:112]  id:1401735262080'
   16 = {str} 'frame: _multicall [_callers.py:39]  id:1401664137936'
   17 = {str} 'frame: _hookexec [_manager.py:80]  id:1401735369312'
   18 = {str} 'frame: __call__ [_hooks.py:265]  id:1401587037584'
   19 = {str} 'frame: pytest_runtestloop [main.py:349]  id:1401606883424'
   20 = {str} 'frame: _multicall [_callers.py:39]  id:1401664134816'
   21 = {str} 'frame: _hookexec [_manager.py:80]  id:1401735368848'
   22 = {str} 'frame: __call__ [_hooks.py:265]  id:1401735335264'
   23 = {str} 'frame: _main [main.py:324]  id:1401671867248'
   24 = {str} 'frame: wrap_session [main.py:270]  id:1401587269712'
   25 = {str} 'frame: pytest_cmdline_main [main.py:317]  id:1401672181568'
   26 = {str} 'frame: _multicall [_callers.py:39]  id:1401587036336'
   27 = {str} 'frame: _hookexec [_manager.py:80]  id:1401588468288'
   28 = {str} 'frame: __call__ [_hooks.py:265]  id:1401670609760'
   29 = {str} 'frame: main [__init__.py:167]  id:1401604356000'
   30 = {str} 'frame: <module> [_jb_pytest_runner.py:51]  id:1401616970464'
   31 = {str} 'frame: execfile [_pydev_execfile.py:18]  id:1401615593152'
   32 = {str} 'frame: _exec [pydevd.py:1496]  id:1401619579968'
   33 = {str} 'frame: run [pydevd.py:1489]  id:1401587023680'
   34 = {str} 'frame: main [pydevd.py:2177]  id:1401588461888'
   35 = {str} 'frame: <module> [pydevd.py:2195]  id:1401546120256'
   __len__ = {int} 36
forestbat wrote this answer on 2022-11-19

I cut my code to another python file and the problem disappeared, if you hope me give more information, I will reopen the issue.

More Details About Repo
Owner Name pandas-dev
Repo Name pandas
Full Name pandas-dev/pandas
Language Python
Created Date 2010-08-24
Updated Date 2022-12-07
Star Count 36164
Watcher Count 1118
Fork Count 15472
Issue Count 3683

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
[RFC] Proposal: uninterruptible overload timeouts (overload2) 20 2022-08-28 2022-12-04
Cutoff and epsilon values 0 2022-07-05 2022-12-02
Cannot establish VPN connection with vpn-slice 1 2021-10-08 2022-11-30
Request and Response Content-Length Must Use Bytes Count 2 2021-04-02 2022-10-07
Aggregation-count, with [data-groups] enabled, counts higher data-group rows 2 2021-08-27 2022-10-08
Map popup can't be dissabled 0 2021-08-13 2022-10-08
new lesson suggestion: using pipeline dsl 0 2020-11-25 2022-11-16
github branch master for gist doesn't work 0 2022-08-12 2022-11-16
Model Inference Speed 3 2021-12-09 2022-10-19
Shopping Cart "Continue shopping" button unresponsive 0 2021-08-27 2022-11-24
FlowSpec traffic-rate dosen't support 2-bytes as? 6 2018-11-26 2022-10-01
manage.py qcleanup fails with error 1 2022-07-08 2022-11-25
Error creating or updating private endpoint - Operation returned an invalid status code 'Forbidden' 7 2021-12-29 2022-11-21
IE11/ES5 minimum support 2 2021-02-27 2021-11-27
Null handling in F#+ 5 2020-11-13 2022-10-21
PHP 8.1.0 Errors / Deprications 70 2021-11-10 2022-11-23
Add rounded corners 1 2021-07-05 2022-01-23
[Port] Update Plotting Documentation 0 2021-11-11 2022-11-16
Make default `begin ... end` rather than `let` 4 2021-06-16 2022-12-05
Import is slow with inline field in aunique 6 2021-11-13 2022-10-19
Exporting general stats table - missingness 18 2021-08-13 2022-12-05
http-post module –– with xml snippet 10 2022-04-27 2022-11-28
egrep is depricated warning 5 2022-09-21 2022-11-25
Navigator.lua broken 5 2021-07-04 2022-10-21
Jackson 2.13.0 compatibility 6 2021-12-14 2022-11-13
Wind improvements 1 2021-03-15 2022-01-12
Update policies allowed/required for ETSI audits 6 2017-05-17 2022-10-10
manifest for mailcow/sogo:1.111 not found @ Amoogust Update 2022 Revision B 5 2022-09-08 2022-12-05
ceph disk usage reported by prometheus does not match linux df command output 4 2022-04-01 2022-06-18
Finish the auth related endpoints 1 2020-11-08 2022-12-04
Support burning Windows 11 images 6 2022-04-20 2022-11-06
neorg not automatically generating metadata anymore 1 2022-01-30 2022-10-08
Mongodb unique index is being dropped magically 2 2021-10-12 2022-10-27
在ubuntu系统训练时,找不到train.txt目录 3 2022-01-07 2022-08-15
planner: cost trace for pushed-down Selection in explain results is not correct 0 2022-02-28 2022-08-15
Dynamically Change Localization Within a Process 2 2022-09-30 2022-10-29
UART.read not working properly on ESP32 (data "shifted" by one) 5 2017-08-04 2022-12-05
[BUG][KOTLIN][JACKSON] JSON serialization of HTTP body data types yields duplicate ouput of field used as polymorphism discriminator 0 2022-01-18 2022-10-25
[BUG][csharp-netcore] Memory leak in ApiClient 4 2022-01-18 2022-10-25
usb device disconnects after certain time. 24 2021-08-17 2022-10-09
Add "X-Zalando-Customer" to the Rule 183 2 2021-06-29 2022-10-31
ClientPNCounterTest.testClusterRestart [API-1215] 1 2021-12-22 2022-08-06
[Feature] add plugin.jdbc.trace_sql_parameters into agent CDS 7 2022-05-10 2022-11-04
The issue with the track that includes <rtept> points 2 2021-09-01 2022-10-11
Num version don't match libpq format for version >10 3 2021-03-16 2022-11-23
Incorrect position when drawing 4 2022-07-08 2022-07-05
ingressclass.kubernetes.io/is-default-class: "true" does not work 13 2021-09-05 2022-10-27
Invalid links 2 2021-04-09 2022-01-23
dial tcp: lookup domain on 127.0.0.11:53: no such host 10 2018-02-15 2022-12-04
nvidia-dkms-510 and nvidia-dkms-470 fail to configure if cc alternative points to clang 0 2022-05-11 2022-11-25