Repository: modin-project/modin

Issue:
Modin read_csv error # File exists but does not read # 

### System information

OS Mojave 10.14.6
installed modin : pip install modin
- **Modin version**:  0.63
- **Python version**: 3.75

### Describe the problem

modin does not read the file that exists in directory using read.csv

### Source code / logs

import pathlib, os
import modin.pandas as pd
import numpy as np

home_path = pathlib.Path.home()  # PosixPath('/Users/AlVinjamur') on MAC
data_path = home_path /'Dropbox.....
os.chdir(data_path)

!ls
#—— gives me these file -----
CL_q.csv          ES_q.parquet      dask-worker-space
CL_t.csv          ES_t.csv          es_q_small.csv
ES_q.csv          ES_t.parquet      es_t_small.csv
——

qdf = pd.read_csv("ES_q.csv")




---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-5-76b7ee285685> in <module>
----> 1 qdf = pd.read_csv("ES_q.csv")

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/pandas/io.py in parser_func(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
     95         if not kwargs.get("sep", sep):
     96             kwargs["sep"] = "\t"
---> 97         return _read(**kwargs)
     98 
     99     return parser_func

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/pandas/io.py in _read(**kwargs)
    108         kwargs: Keyword arguments in pandas.read_csv
    109     """
--> 110     pd_obj = BaseFactory.read_csv(**kwargs)
    111     # This happens when `read_csv` returns a TextFileReader object for iterating through
    112     if isinstance(pd_obj, pandas.io.parsers.TextFileReader):

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/data_management/factories.py in read_csv(cls, **kwargs)
     50     @classmethod
     51     def read_csv(cls, **kwargs):
---> 52         return cls._determine_engine()._read_csv(**kwargs)
     53 
     54     @classmethod

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/data_management/factories.py in _read_csv(cls, **kwargs)
     54     @classmethod
     55     def _read_csv(cls, **kwargs):
---> 56         return cls.io_cls.read_csv(**kwargs)
     57 
     58     @classmethod

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/engines/base/io/text/csv_reader.py in read(cls, filepath_or_buffer, **kwargs)
    195         # or based on the column(s) that were requested.
    196         if index_col is None:
--> 197             row_lengths = cls.materialize(index_ids)
    198             new_index = pandas.RangeIndex(sum(row_lengths))
    199         else:

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/engines/dask/task_wrapper.py in materialize(cls, future)
     18     def materialize(cls, future):
     19         client = _get_global_client()
---> 20         return client.gather(future)

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/distributed/client.py in gather(self, futures, errors, direct, asynchronous)
   1870                 direct=direct,
   1871                 local_worker=local_worker,
-> 1872                 asynchronous=asynchronous,
   1873             )
   1874 

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/distributed/client.py in sync(self, func, asynchronous, callback_timeout, *args, **kwargs)
    765         else:
    766             return sync(
--> 767                 self.loop, func, *args, callback_timeout=callback_timeout, **kwargs
    768             )
    769 

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/distributed/utils.py in sync(loop, func, callback_timeout, *args, **kwargs)
    332     if error[0]:
    333         typ, exc, tb = error[0]
--> 334         raise exc.with_traceback(tb)
    335     else:
    336         return result[0]

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/distributed/utils.py in f()
    316             if callback_timeout is not None:
    317                 future = gen.with_timeout(timedelta(seconds=callback_timeout), future)
--> 318             result[0] = yield future
    319         except Exception as exc:
    320             error[0] = sys.exc_info()

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/tornado/gen.py in run(self)
    733 
    734                     try:
--> 735                         value = future.result()
    736                     except Exception:
    737                         exc_info = sys.exc_info()

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/distributed/client.py in _gather(self, futures, errors, direct, local_worker)
   1726                             exc = CancelledError(key)
   1727                         else:
-> 1728                             raise exception.with_traceback(traceback)
   1729                         raise exc
   1730                     if errors == "skip":

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/backends/pandas/parsers.py in parse()
     59         if start is not None and end is not None:
     60             # pop "compression" from kwargs because bio is uncompressed
---> 61             bio = FileReader.file_open(fname, "rb", kwargs.pop("compression", "infer"))
     62             if kwargs.pop("encoding", False):
     63                 header = b"" + bio.readline()

~/anaconda3/envs/tickresearch/lib/python3.7/site-packages/modin/engines/base/io/file_reader.py in file_open()
     58                         )
     59 
---> 60         return open(file_path, mode=mode)
     61 
     62     @classmethod

FileNotFoundError: [Errno 2] No such file or directory: 'ES_q.csv'





Discussion:
Hi @alvinjamur, thanks for posting!

It looks like the workers start in a different working directory than the parent. Do you still get the error if you move the `import modin.pandas as pd` to below the `os.chdir`?

This bug can be fixed if we pass the full path to the workers instead of just the filename. Thanks for posting this, I will get this fixed as soon as I can!
When I pass in the full path to the file, it seems to work just fine.
I'm so happy.....these files I have are Yuuuuuuuuge!

===
import numpy as np
import pathlib, os

home_path = pathlib.Path.home()          # PosixPath('/Users/AlVinjamur') on MAC

filename = 'ES_t.csv'

data_path = home_path /'Dropbox (aLV)/COMPUTING/DATA/TICK_DATA/TICK_DATA_SAMPLE/SPECIAL_SAMPLE'

file_path = file_path = home_path /'Dropbox (aLV)/COMPUTING/DATA/TICK_DATA/TICK_DATA_SAMPLE/SPECIAL_SAMPLE' / filename

os.chdir(data_path)

import modin.pandas as pd
import numpy as np

tdf = pd.read_csv(file_path)




Resolving patch:
diff --git a/modin/engines/base/io/file_reader.py b/modin/engines/base/io/file_reader.py
--- a/modin/engines/base/io/file_reader.py
+++ b/modin/engines/base/io/file_reader.py
@@ -10,6 +10,13 @@ class FileReader:
     frame_partition_cls = None
     query_compiler_cls = None
 
+    @classmethod
+    def get_path(cls, file_path):
+        if S3_ADDRESS_REGEX.search(file_path):
+            return file_path
+        else:
+            return os.path.abspath(file_path)
+
     @classmethod
     def file_open(cls, file_path, mode="rb", compression="infer"):
         if isinstance(file_path, str):
diff --git a/modin/engines/base/io/text/csv_reader.py b/modin/engines/base/io/text/csv_reader.py
--- a/modin/engines/base/io/text/csv_reader.py
+++ b/modin/engines/base/io/text/csv_reader.py
@@ -61,6 +61,7 @@ def read(cls, filepath_or_buffer, **kwargs):
         if isinstance(filepath_or_buffer, str):
             if not cls.file_exists(filepath_or_buffer):
                 return cls.single_worker_read(filepath_or_buffer, **kwargs)
+            filepath_or_buffer = cls.get_path(filepath_or_buffer)
         elif not isinstance(filepath_or_buffer, py.path.local):
             read_from_pandas = True
             # Pandas read_csv supports pathlib.Path
diff --git a/modin/engines/base/io/text/json_reader.py b/modin/engines/base/io/text/json_reader.py
--- a/modin/engines/base/io/text/json_reader.py
+++ b/modin/engines/base/io/text/json_reader.py
@@ -8,6 +8,7 @@
 class JSONReader(TextFileReader):
     @classmethod
     def read(cls, path_or_buf, **kwargs):
+        path_or_buf = cls.get_path(path_or_buf)
         if not kwargs.get("lines", False):
             return cls.single_worker_read(path_or_buf, **kwargs)
         columns = pandas.read_json(


Test patch: