-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API/BUG: Make to_json
index=
arg consistent with orient
arg
#52143
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
Changes from 6 commits
8c8e73f
32ba1ab
64e14c3
636b417
38bea0a
2ef117c
89cf3c5
38b81b2
ec728d2
8aef2dd
3d84579
d53b9f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ def to_json( | |
default_handler: Callable[[Any], JSONSerializable] | None = ..., | ||
lines: bool = ..., | ||
compression: CompressionOptions = ..., | ||
index: bool = ..., | ||
index: bool | None = ..., | ||
indent: int = ..., | ||
storage_options: StorageOptions = ..., | ||
mode: Literal["a", "w"] = ..., | ||
|
@@ -122,7 +122,7 @@ def to_json( | |
default_handler: Callable[[Any], JSONSerializable] | None = ..., | ||
lines: bool = ..., | ||
compression: CompressionOptions = ..., | ||
index: bool = ..., | ||
index: bool | None = ..., | ||
indent: int = ..., | ||
storage_options: StorageOptions = ..., | ||
mode: Literal["a", "w"] = ..., | ||
|
@@ -141,14 +141,25 @@ def to_json( | |
default_handler: Callable[[Any], JSONSerializable] | None = None, | ||
lines: bool = False, | ||
compression: CompressionOptions = "infer", | ||
index: bool = True, | ||
index: bool | None = None, | ||
indent: int = 0, | ||
storage_options: StorageOptions = None, | ||
mode: Literal["a", "w"] = "w", | ||
) -> str | None: | ||
if not index and orient not in ["split", "table"]: | ||
if index is None and orient in ["records", "values"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this branch necessary? Or can you just change L151 to set it to True for appropriate orients? |
||
index = False | ||
elif index is None: | ||
index = True | ||
|
||
if not index and orient in ["index", "columns"]: | ||
raise ValueError( | ||
"'index=False' is only valid when 'orient' is 'split', 'table', " | ||
"'records', or 'values'." | ||
) | ||
elif index and orient in ["records", "values"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The orient check is the same here as on L149 - can these not be consolidated? |
||
raise ValueError( | ||
"'index=False' is only valid when 'orient' is 'split' or 'table'" | ||
"'index=True' is only valid when 'orient' is 'split', 'table', " | ||
"'index', or 'columns'. Convert index to column for other orients." | ||
) | ||
|
||
if lines and orient != "records": | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be easier to just say that the index is only used in split, index, column and table orients. Of those formats, index and column cannot be False.
You are kind of doing this now but I think in a way that is a bit more confusing. If you structure the commentary and code this will I think will help simplify the logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some changes, let me know what you think!