Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-5302

Memory leak when read_table().to_pandas().to_json()

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Bug
    • Affects Version/s: 0.13.0
    • Fix Version/s: None
    • Component/s: Python
    • Labels:
    • Environment:
      Linux, Python 3.6.4 :: Anaconda, Inc.

      Description

      The following piece of code (running on a Linux, Python 3.6 from anaconda) demonstrates a memory leak when reading data from disk.

      import resource
      
      import pandas as pd
      import pyarrow as pa
      import pyarrow.parquet as pq
      
      
      # some random data, some of them as array columns
      path = 'data.parquet'
      batches = 5000
      df = pd.DataFrame({
          't': [list(range(0, 180 * 60, 5))] * batches,
      })
      
      pq.write_table(pa.Table.from_pandas(df), path)
      
      table = pq.read_table(path)
      
      
      # read the data above and convert it to json (e.g. the backend of a restful API)
      for i in range(100):
          # comment any of the 2 lines for the leak to vanish.
          df = pq.read_table(path).to_pandas()
          df['t'].to_json()
          print(resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
      
      

      Result :

      481676
      618584
      755396
      892156
      1028892
      1165660
      1302428
      1439184
      1620376
      1801340
      ...

      Relevant pip freeze:

      pyarrow (0.13.0)

      pandas (0.24.2)

       

      Note: it is not entirely obvious that this is caused by pyarrow instead of pandas or numpy. I was only able to reproduce it through write/read from pyarrow.

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jorgecarleitao Jorge
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: