Skip to content

[BUG] read_parquet reads incorrect values when requested to read a portion of a file #7113

Closed

Description

@magnatelee

Describe the bug
read_parquet reads incorrect values when skiprows and num_rows are set.

Steps/Code to reproduce bug

  1. Download and unzip this parquet file: test.parquet.zip
  2. Run this reproducer:
import cudf                                                                                                                                                                                                                       
                                                                                                                                                                                                                                  
x = cudf.read_parquet("test.parquet")                                                                                                                                                                                             
y = cudf.read_parquet("test.parquet", skiprows=45000, num_rows=45000)                                                                                                                                                             
                                                                                                                                                                                                                                  
for column in x.columns:                                                                                                                                                                                                          
    print(f"##### Testing {column} (dtype: {x.dtypes[column]}) #####")                                                                                                                                                             
    assert x[45000:90000][column].equals(y[column])                                                                                                                                                                               

The code should pass all assertions, but fails on a column with float32 type (and it would fail on column imp_end_date with float64 type if I let it pass this one):

##### Testing imp_sk (dtype: int64) #####
##### Testing imp_item_sk (dtype: int64) #####
##### Testing imp_competitor (dtype: object) #####
##### Testing imp_competitor_price (dtype: float32) #####
Traceback (most recent call last):
  File "reproducer.py", line 8, in <module>
    assert x[45000:90000][column].equals(y[column])
AssertionError

Expected behavior
The reproducer should pass all the assertions.

Environment overview (please complete the following information)

Environment details
print_env.sh.log

Activity

  1. added
    bug
    Needs Triage
    on Jan 11, 2021
  2. added
    cuIO
    and removed
    Needs Triage
    on Jan 11, 2021
  3. kkraus14 commented on Jan 11, 2021

    @kkraus14
    Contributor
  4. devavret commented on Jan 11, 2021

    @devavret
    Contributor

    The data for imp_competitor_price seems to be shifted by 15 indices. Looking...

    In [30]: x['imp_competitor_price'][45015:45020]
    Out[30]: 
    45015    58.590000
    45016    70.959999
    45017    20.129999
    45018    85.370003
    45019    16.010000
    Name: imp_competitor_price, dtype: float32
    
    In [32]: y['imp_competitor_price']
    Out[32]: 
    45000    58.590000
    45001    70.959999
    45002    20.129999
    45003    85.370003
    45004    16.010000
               ...    
  5. devavret commented on Jan 12, 2021

    @devavret
    Contributor

    I think I know what's going on. Parquet stores data without nulls. It assumes that the nulls will be indicated by the definition levels. So a column containing [1, null, 3] is stored as data=[1,3], def_level=[1,0,1]. There are nulls in the float32 column.

    In [10]: x.index[x.imp_competitor_price.isnull()]
    Out[10]: 
    Int64Index([ 4537, 14025, 17201, 22867, 22906, 25493, 26668, 28690, 29261,
                35369, 37690, 39619, 41810, 42902, 43065, 49855, 50067, 60799,
                63599, 65968, 66229, 71490, 71542, 72322, 73232, 75641, 76996,
                78143, 80077],
               dtype='int64')

    That means skipping the rows till after e.g. 4537 would mean that the reader doesn't know about the nulls that came before it. That's why reading after 4537 would cause a shift by 1 in the data.

    In [13]: import cudf
        ...: import pandas as pd
        ...: 
        ...: x = pd.read_parquet("test.parquet")
        ...: x = cudf.from_pandas(x)
        ...: y = cudf.read_parquet("test.parquet", skiprows=4530, num_rows=10)
        ...: print(y.imp_competitor_price, '\n', x.imp_competitor_price[4530:4540])
    
    4530    83.91999817
    4531    97.23000336
    4532    33.63000107
    4533    88.27999878
    4534    21.51000023
    4535    46.22000122
    4536    85.40000153
    4537           <NA>
    4538    5.010000229
    4539    36.56000137
    Name: imp_competitor_price, dtype: float32 
     4530    83.91999817
    4531    97.23000336
    4532    33.63000107
    4533    88.27999878
    4534    21.51000023
    4535    46.22000122
    4536    85.40000153
    4537           <NA>
    4538    5.010000229
    4539    36.56000137
    Name: imp_competitor_price, dtype: float32
    
    In [15]: y = cudf.read_parquet("test.parquet", skiprows=4540, num_rows=10)
        ...: print(y.imp_competitor_price, '\n', x.imp_competitor_price[4540:4550])
    
    4540    31.809999
    4541    22.129999
    4542    33.209999
    4543    27.930000
    4544    37.270000
    4545    91.330002
    4546    17.010000
    4547    96.250000
    4548    46.009998
    4549    55.529999
    Name: imp_competitor_price, dtype: float32 
     4540    34.720001
    4541    31.809999
    4542    22.129999
    4543    33.209999
    4544    27.930000
    4545    37.270000
    4546    91.330002
    4547    17.010000
    4548    96.250000
    4549    46.009998
    Name: imp_competitor_price, dtype: float32

    And the shifts add up the more nulls we skip.

  6. added
    libcudf
    on Jan 12, 2021
  7. devavret commented on Jan 15, 2021

    @devavret
    Contributor

    Tracked this down to the fact that the logic to find the rows to skip due to the presence of nulls is only active for lists. (gpuUpdatePageSizes is only called by PreprocessColumnData, which is only called for lists).

    Updated @nvdbaranec offline and passing this to him.

  8. github-actions commented on Feb 16, 2021

    @github-actions

    This issue has been marked stale due to no recent activity in the past 30d. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be marked rotten if there is no activity in the next 60d.

  9. nvdbaranec commented on Feb 16, 2021

    @nvdbaranec
    Contributor

    This is still being addressed. Haven't had time to switch back to it, but it needs to be fixed.

  10. nvdbaranec commented on Mar 17, 2021

    @nvdbaranec
    Contributor

    PR with the fix is up if anyone is up for testing with your original repro case.

    #7627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcuIOlibcudf

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions