AttributeError: module 'pandas._libs.tslibs.parsing' has no attribute 'parse_time_string' Wrong step or date format in XML settings file Input 02/01/1990 06:00
Closed this issue · 6 comments
As on the previous issue, please provide further info about the problem (lisflood version, XML file).
Please provide here also the versions of the installed packages in your environment (by typing "pip list")
Thanks
Carlo
Running into the same issue.
OS: Ubuntu 22.04.2 LTS
Python: 3.9.16
Git Commit: 4d1f2ed (lisflood-model)
Installed Libraries
cython 0.29.35 pypi_0 pypi
dask 2023.5.0 pyhd8ed1ab_0 conda-forge
dask-core 2023.5.0 pyhd8ed1ab_0 conda-forge
gdal 3.6.4 py39h5a35a9c_3 conda-forge
netcdf4 1.6.3 nompi_py39h369ccc5_102 conda-forge
numba 0.57.0 pypi_0 pypi
numpy 1.24.3 py39h6183b62_0 conda-forge
pcraster 4.4.0 py39h07ce518_2 conda-forge
gdal 3.6.4 py39h5a35a9c_3 conda-forge
libgdal 3.6.4 h272c690_3 conda-forge
xarray 2023.5.0 pyhd8ed1ab_0 conda-forge
Clone and install Lisflood-code
$ git clone --depth 1 https://github.com/ec-jrc/lisflood-code.git
$ cd lisflood-code
$ pip install -e .
Check Lisflood Version
$lisflood
LisfloodPy - Lisflood using pcraster Python framework
Authors: Ad de Roo, Emiliano Gelati, Peter Burek, Johan van der Knijff, Niko Wanders
Version: 4.1.2
Date: 22/03/2023
Status: Operation
Arguments list:
settings.xml settings file
-q --quiet output progression given as .
-v --veryquiet no output progression is given
-l --loud output progression given as time step, date and discharge
-c --check input maps and stack maps are checked, output for each input map BUT no model run
-h --noheader .tss file have no header and start immediately with the time series
-d --debug debug outputs
-i --initonly only run initialisation, not the dynamic loop
Attempt to run tests to verify that installation was successful
$ cd lisflood-code
$ pytest --maxfail=1 tests/
============================= test session starts ==============================
platform linux -- Python 3.9.16, pytest-7.3.1, pluggy-1.0.0 -- /opt/conda/bin/python3.9
cachedir: .pytest_cache
rootdir: /tmp/lisflood-code
configfile: pytest.ini
plugins: cov-4.1.0, mock-3.10.0, anyio-3.6.2
collecting ... collected 68 items / 16 deselected / 52 selected
tests/test_caching.py::TestCaching::test_caching_24h FAILED [ 1%]
=================================== FAILURES ===================================
_________________________ TestCaching.test_caching_24h _________________________
date_in = '31/12/1999 06:00', calendar_type = 'proleptic_gregorian'
def calendar(date_in, calendar_type='proleptic_gregorian'):
""" Get date or number of steps from input.
Get date from input string using one of the available formats or get time step number from input number or string.
Used to get the date from CalendarDayStart (input) in the settings xml
:param date_in: string containing a date in one of the available formats or time step number as number or string
:param calendar_type:
:rtype: datetime object or float number
:returns: date as datetime or time step number as float
:raises ValueError: stop if input is not a step number AND it is in wrong date format
"""
try:
# try reading step number from number or string
> return float(date_in)
E ValueError: could not convert string to float: '31/12/1999 06:00'
_t_units = 'hours since 1970-01-01 00:00:00'
calendar_type = 'proleptic_gregorian'
date_in = '31/12/1999 06:00'
msg = 'Wrong step or date format in XML settings file\n Input 31/12/1999 06:00'
src/lisflood/global_modules/settings.py:614: ValueError
During handling of the above exception, another exception occurred:
date_in = '31/12/1999 06:00', calendar_type = 'proleptic_gregorian'
def calendar(date_in, calendar_type='proleptic_gregorian'):
""" Get date or number of steps from input.
Get date from input string using one of the available formats or get time step number from input number or string.
Used to get the date from CalendarDayStart (input) in the settings xml
:param date_in: string containing a date in one of the available formats or time step number as number or string
:param calendar_type:
:rtype: datetime object or float number
:returns: date as datetime or time step number as float
:raises ValueError: stop if input is not a step number AND it is in wrong date format
"""
try:
# try reading step number from number or string
return float(date_in)
except ValueError:
# try reading a date in one of available formats
try:
_t_units = "hours since 1970-01-01 00:00:00" # units used for date type conversion (datetime.datetime -> calendar-specific if needed)
> date = parsing.parse_time_string(date_in, dayfirst=True)[0] # datetime.datetime type
E AttributeError: module 'pandas._libs.tslibs.parsing' has no attribute 'parse_time_string'
_t_units = 'hours since 1970-01-01 00:00:00'
calendar_type = 'proleptic_gregorian'
date_in = '31/12/1999 06:00'
msg = 'Wrong step or date format in XML settings file\n Input 31/12/1999 06:00'
src/lisflood/global_modules/settings.py:619: AttributeError
During handling of the above exception, another exception occurred:
self = <tests.test_caching.TestCaching object at 0x7fcc0dab5760>
def test_caching_24h(self):
dt_sec = 86400
> self.run_lisflood_caching(dt_sec)
dt_sec = 86400
self = <tests.test_caching.TestCaching object at 0x7fcc0dab5760>
tests/test_caching.py:24:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
...
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
date_in = '31/12/1999 06:00', calendar_type = 'proleptic_gregorian'
def calendar(date_in, calendar_type='proleptic_gregorian'):
""" Get date or number of steps from input.
Get date from input string using one of the available formats or get time step number from input number or string.
Used to get the date from CalendarDayStart (input) in the settings xml
:param date_in: string containing a date in one of the available formats or time step number as number or string
:param calendar_type:
:rtype: datetime object or float number
:returns: date as datetime or time step number as float
:raises ValueError: stop if input is not a step number AND it is in wrong date format
"""
try:
# try reading step number from number or string
return float(date_in)
except ValueError:
# try reading a date in one of available formats
try:
_t_units = "hours since 1970-01-01 00:00:00" # units used for date type conversion (datetime.datetime -> calendar-specific if needed)
date = parsing.parse_time_string(date_in, dayfirst=True)[0] # datetime.datetime type
step = date2num(date, _t_units, calendar_type) # float type
return num2date(step, _t_units, calendar_type) # calendar-dependent type from netCDF4.netcdftime._netcdftime module
except:
# if cannot read input then stop
msg = "Wrong step or date format in XML settings file\n Input {}".format(date_in)
> raise LisfloodError(msg)
E lisflood.global_modules.errors.LisfloodError:
E
E ========================== LISFLOOD ERROR =============================
E Wrong step or date format in XML settings file
E Input 31/12/1999 06:00
_t_units = 'hours since 1970-01-01 00:00:00'
calendar_type = 'proleptic_gregorian'
date_in = '31/12/1999 06:00'
msg = 'Wrong step or date format in XML settings file\n Input 31/12/1999 06:00'
src/lisflood/global_modules/settings.py:625: LisfloodError
--------------------------- Captured stdout teardown ---------------------------
Cleaning directories and cache
Clearing cache
---------- coverage: platform linux, python 3.9.16-final-0 -----------
Name Stmts Miss Cover
----------------------------------------------------------------------------------
src/lisflood/Lisflood_EnKF.py 21 12 43%
src/lisflood/Lisflood_dynamic.py 102 91 11%
src/lisflood/Lisflood_initial.py 245 177 28%
src/lisflood/Lisflood_monteCarlo.py 11 4 64%
src/lisflood/__init__.py 13 1 92%
src/lisflood/global_modules/__init__.py 0 0 100%
src/lisflood/global_modules/add1.py 556 502 10%
src/lisflood/global_modules/checkers.py 38 23 39%
src/lisflood/global_modules/decorators.py 64 23 64%
src/lisflood/global_modules/default_options.py 4 0 100%
src/lisflood/global_modules/errors.py 28 12 57%
src/lisflood/global_modules/netcdf.py 301 257 15%
src/lisflood/global_modules/output.py 202 188 7%
src/lisflood/global_modules/settings.py 451 261 42%
src/lisflood/global_modules/stateVar.py 93 86 8%
src/lisflood/global_modules/zusatz.py 238 198 17%
src/lisflood/hydrological_modules/__init__.py 43 31 28%
src/lisflood/hydrological_modules/evapowater.py 74 60 19%
src/lisflood/hydrological_modules/frost.py 21 11 48%
src/lisflood/hydrological_modules/groundwater.py 71 59 17%
src/lisflood/hydrological_modules/indicatorcalc.py 126 112 11%
src/lisflood/hydrological_modules/inflow.py 62 45 27%
src/lisflood/hydrological_modules/kinematic_wave_parallel.py 105 70 33%
src/lisflood/hydrological_modules/lakes.py 124 110 11%
src/lisflood/hydrological_modules/landusechange.py 86 71 17%
src/lisflood/hydrological_modules/leafarea.py 42 28 33%
src/lisflood/hydrological_modules/miscInitial.py 77 65 16%
src/lisflood/hydrological_modules/opensealed.py 20 11 45%
src/lisflood/hydrological_modules/polder.py 27 13 52%
src/lisflood/hydrological_modules/readmeteo.py 30 23 23%
src/lisflood/hydrological_modules/reservoir.py 131 116 11%
src/lisflood/hydrological_modules/riceirrigation.py 54 42 22%
src/lisflood/hydrological_modules/routing.py 257 238 7%
src/lisflood/hydrological_modules/snow.py 64 52 19%
src/lisflood/hydrological_modules/soil.py 236 222 6%
src/lisflood/hydrological_modules/soilloop.py 308 267 13%
src/lisflood/hydrological_modules/structures.py 15 8 47%
src/lisflood/hydrological_modules/surface_routing.py 63 50 21%
src/lisflood/hydrological_modules/transmission.py 29 18 38%
src/lisflood/hydrological_modules/waterabstraction.py 301 285 5%
src/lisflood/hydrological_modules/waterbalance.py 107 98 8%
src/lisflood/hydrological_modules/waterlevel.py 27 16 41%
src/lisflood/hydrological_modules/wateruse.py 8 3 62%
src/lisflood/main.py 96 70 27%
----------------------------------------------------------------------------------
TOTAL 4971 4029 19%
=========================== short test summary info ============================
FAILED tests/test_caching.py::TestCaching::test_caching_24h - lisflood.global...
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
======================= 1 failed, 16 deselected in 1.72s =======================
Dear @Castronova
Can you please share your output of the "pip list" command? It seems an issue with the version of pandas
Thanks
Carlo
@doc78 Here is what's installed in my environment. I should also note that I'm installing this inside a Docker image.
Environment.yaml
name: base
channels:
- conda-forge
- defaults
dependencies:
- bokeh=3.1.1
- cudatoolkit=9.0
- curl=8.1.1
- dask=2023.5.0
- dask-core=2023.5.0
- distributed=2023.5.0
- fiona=1.8.22
- folium=0.14.0
- fsspec=2023.5.0
- gdal=3.6.4
- geemap=0.20.7
- geopandas=0.13.0
- h5py=3.8.0
- hdf5=1.14.0
- holoviews=1.16.0
- ipyleaflet=0.17.2
- ipympl=0.9.3
- jupyter-resource-usage=0.7.1
- jupyter-server-proxy=4.0.0
- jupyter_client=8.2.0
- matplotlib=3.7.1
- nb_conda_kernels=2.3.1
- netcdf4=1.6.3
- networkx=3.1
- numpy=1.24.3
- pandas=2.0.1
- pillow=9.5.0
- proj=9.2.0
- pyproj=3.5.0
- pyshp=2.3.1
- python=3.9.16
- pytorch=2.0.0
- rasterio=1.3.7
- rasterstats=0.18.0
- requests=2.31.0
- scikit-learn=1.2.2
- scipy=1.10.1
- shapely=2.0.1
- sympy=1.12
- xarray=2023.5.0
- pip=23.1.2
- pcraster=4.4.0
requirements.txt
lisflood-model
It looks like this function was renamed in Jan 2023.
Ok, thus a quick fix would be to install pandas<2 (I'm using version 1.3.5).
I will take note of this for future releases
Thanks
Carlo