-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
pandas.errors.InvalidIndexError raised when running computation in parallel using dask #7059
Comments
xref #6904 (not sure it is 100% relevant, but the problem also arises when |
@benbovy thanks for the hint! I tried passing an explicit lock to |
I have managed to reduce the reproducing example (see "Minimal Complete Verifiable Example 2" above) and then also find a proper solution to fix this issue. I am still not sure whether this is a bug or intended behavior, so I'll won't close the issue for now. Basically the issue occurs when a chunked NetCDF file is loaded from disk, passed to
This seems to fix this issue and seems to be the proper solution anyway. I still don't see why I am not allowed to use |
I've had the same issues under the exact same conditions. However, it happens whether I use dask or not. This solution fixes it, but I agree at least a doc update would be helpful! |
I agree with just passing all args explicitly. Does it work otherwise with As a side note, this particular example seems quite convoluted.
|
What do you mean by that?
Uhm yes, you are right, this should be removed, not sure how this happened. Removing
Oh wow, thanks! Haven't seen flox before. |
Thanks for raising. I too am intermittently hitting this Using |
@itcarroll did you see my comment above how I fixed my issue? Are you using shadowed variables in your worker function? |
My guess is that this is just because of:
...and dask is just one way of running multi-threading. If that's the case, we should be able to repro with a much smaller example, just running |
What happened?
I'm doing a computation using chunks and
map_blocks()
to run things in parallel. At some point apandas.errors.InvalidIndexError
is raised. When using dask's synchronous scheduler, everything works fine. I thinkpandas.core.indexes.base.Index
is not thread-safe. At least this seems to be the place of the race condition. See further tests below.(This issue was initially discussed in #6816, but the ticket was closed, because I couldn't reproduce the problem any longer. Now it seems to be reproducible in every run, so it is time for a proper bug report, which is this ticket here.)
What did you expect to happen?
Dask schedulers
single-threaded
andthreads
should have the same result.Minimal Complete Verifiable Example 1
Edit: I've managed to reduce the verifiable example, see example 2 below.
Minimal Complete Verifiable Example 2
MVCE confirmation
Relevant log output
This is the traceback of "Minimal Complete Verifiable Example 1".
Anything else we need to know?
Workaround: Use synchronous dask scheduler
The issue does not occur if I use the synchronous dask scheduler by adding at the very beginning of my script:
dask.config.set(scheduler='single-threaded')
Additional debugging print
If I add the following debugging print to the pandas code:
...I get the following output:
So the index seems to be unique, but
self.is_unique
isFalse
for some reason (note thatnot self._index_as_unique
andself.is_unique
is the same in this case).Proof of race condtion: addd sleep 1s
To confirm that the race condition is at this point we wait for 1s and then check again for uniqueness:
This outputs:
Environment
xarray: 0.15.0
pandas: 0.25.3
numpy: 1.17.4
scipy: 1.3.3
netCDF4: 1.5.3
pydap: None
h5netcdf: 0.7.1
h5py: 2.10.0
Nio: None
zarr: 2.4.0+ds
cftime: 1.1.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.1.3
cfgrib: None
iris: None
bottleneck: 1.2.1
dask: 2.8.1+dfsg
distributed: None
matplotlib: 3.1.2
cartopy: None
seaborn: 0.10.0
numbagg: None
setuptools: 45.2.0
pip3: None
conda: None
pytest: 4.6.9
IPython: 7.13.0
sphinx: 1.8.5
The text was updated successfully, but these errors were encountered: