Skip to content

[BUG] to_json ignores index=True #11317

@dagardner-nv

Description

@dagardner-nv

Describe the bug
Documentation for the index argument for cudf.DataFrame.to_json https://docs.rapids.ai/api/cudf/stable/api_docs/api/cudf.DataFrame.to_json.html
states:

indexbool, default True
Whether to include the index values in the JSON string. Not including the index (index=False) is only supported when orient is ‘split’ or ‘table’.

However this is ignored, and appears to be caused by Pandas as cudf's to_json uses Panda's to_json.
pandas-dev/pandas#37600

Steps/Code to reproduce bug
Issue can be reproduced in both cudf and pandas.

cudf repro:

import cudf

df = cudf.DataFrame([3,4,5,6])

# Including CSV output for comparison
print(df.to_csv(header=True, index=True))

print(df.to_json(index=True, orient="records"))

Yields this output:

,0
0,3
1,4
2,5
3,6

[{"0":3},{"0":4},{"0":5},{"0":6}]

Pandas repro:

import pandas

df = pandas.DataFrame([3,4,5,6])

# Including CSV output for comparison
print(df.to_csv(header=True, index=True))

print(df.to_json(index=True, orient="records"))

Expected behavior
Include index column when index=True

Environment overview (please complete the following information)

  • Environment location: Bare-metal
  • Method of cuDF install: conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    0 - BacklogIn queue waiting for assignmentbugSomething isn't workingcuIOcuIO issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions