Merged
Changes from all commits
Show all changes
12 commitsSelect commit Hold shift + click to select a range
8c8e73f
API/BUG: Make to_json index= consistent with orient
dshemetov32ba1ab
style: lint
dshemetov64e14c3
style: make mypy happy
dshemetov636b417
review: simplify
dshemetov38bea0a
Merge remote-tracking branch 'upstream/main' into ds/to_json
dshemetov2ef117c
Merge branch 'main' into ds/to_json
dshemetov89cf3c5
review: clarify and consolidate branches
dshemetov38b81b2
style: add explainer comment
dshemetovec728d2
Merge branch 'main' into ds/to_json
dshemetov8aef2dd
doc: change error message in _json
dshemetov3d84579
docs: update whatsnew 2.1.0
dshemetovd53b9f4
docs: sort whatsnew
dshemetovFile filter
Filter by extension
Conversations
Failed to load comments.
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Failed to load files.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -100,7 +100,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"] = ..., | ||
@@ -120,7 +120,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"] = ..., | ||
@@ -139,15 +139,24 @@ 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 orient in ["records", "values"] and index is True: | ||
raise ValueError( | ||
"'index=False' is only valid when 'orient' is 'split' or 'table'" | ||
"'index=True' is only valid when 'orient' is 'split', 'table', " | ||
dshemetov marked this conversation as resolved. Show resolved Hide resolvedUh oh!There was an error while loading. Please reload this page. | ||
"'index', or 'columns'." | ||
) | ||
elif orient in ["index", "columns"] and index is False: | ||
raise ValueError( | ||
"'index=False' is only valid when 'orient' is 'split', 'table', " | ||
"'records', or 'values'." | ||
) | ||
elif index is None: | ||
# will be ignored for orient='records' and 'values' | ||
index = True | ||
if lines and orient != "records": | ||
raise ValueError("'lines' keyword only valid when 'orient' is records") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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
Uh oh!
There was an error while loading. Please reload this page.
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!