-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
REF: dataframe formatters/outputs #36510
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 20 commits
c3568a2
837858f
08e899f
602c984
bd5cb87
6e8d4d8
cbd3c76
5c30924
af8fe98
6e9fb3c
878eed2
d87638b
1292be5
41553f6
a66ca5e
3fbe4ba
733fa34
bfb37d7
f1b494e
75daa74
6e39277
df3b5c6
5a18386
fc68fa5
19d2156
271ef5c
b1018ad
22d0982
94dbadd
914981b
482ccd1
7b57fc8
1e2969f
90977fd
fc7a091
1335a11
b67b481
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import csv as csvlib | ||
from io import StringIO, TextIOWrapper | ||
import os | ||
from typing import Any, Dict, Hashable, Iterator, List, Optional, Sequence, Union | ||
from typing import Any, Dict, Iterator, List, Optional, Sequence | ||
|
||
import numpy as np | ||
|
||
|
@@ -29,19 +29,16 @@ | |
from pandas.core.indexes.api import Index | ||
|
||
from pandas.io.common import get_filepath_or_buffer, get_handle | ||
from pandas.io.formats.format import DataFrameFormatter | ||
|
||
|
||
class CSVFormatter: | ||
def __init__( | ||
self, | ||
obj, | ||
formatter: DataFrameFormatter, | ||
path_or_buf: Optional[FilePathOrBuffer[str]] = None, | ||
sep: str = ",", | ||
na_rep: str = "", | ||
float_format: Optional[str] = None, | ||
cols: Optional[Sequence[Label]] = None, | ||
header: Union[bool, Sequence[Hashable]] = True, | ||
index: bool = True, | ||
index_label: Optional[IndexLabel] = None, | ||
mode: str = "w", | ||
encoding: Optional[str] = None, | ||
|
@@ -54,10 +51,11 @@ def __init__( | |
date_format: Optional[str] = None, | ||
doublequote: bool = True, | ||
escapechar: Optional[str] = None, | ||
decimal=".", | ||
storage_options: StorageOptions = None, | ||
): | ||
self.obj = obj | ||
self.fmt = formatter | ||
|
||
self.obj = self.fmt.frame | ||
|
||
self.encoding = encoding or "utf-8" | ||
|
||
|
@@ -79,11 +77,11 @@ def __init__( | |
self.mode = ioargs.mode | ||
|
||
self.sep = sep | ||
self.na_rep = na_rep | ||
self.float_format = float_format | ||
self.decimal = decimal | ||
self.header = header | ||
self.index = index | ||
self.na_rep = self.fmt.na_rep | ||
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. if these are just readable now (which i think they are in this class as they are now set in DataFrameRenderer), then maybe make these properties? (or is my assumption wrong) 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. Refactored to properties. |
||
self.float_format = self.fmt.float_format | ||
self.decimal = self.fmt.decimal | ||
self.header = self.fmt.header | ||
self.index = self.fmt.index | ||
self.index_label = index_label | ||
self.errors = errors | ||
self.quoting = quoting or csvlib.QUOTE_MINIMAL | ||
|
@@ -161,7 +159,12 @@ def _refine_cols(self, cols: Optional[Sequence[Label]]) -> Sequence[Label]: | |
|
||
# update columns to include possible multiplicity of dupes | ||
# and make sure sure cols is just a list of labels | ||
cols = self.obj.columns | ||
|
||
# Ignore mypy error | ||
# Incompatible types in assignment | ||
# (expression has type "Index", | ||
# variable has type "Optional[Sequence[Optional[Hashable]]]") [assignment] | ||
cols = self.obj.columns # type: ignore[assignment] | ||
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. you are getting this because you are overwriting cols. don't do that. |
||
if isinstance(cols, ABCIndexClass): | ||
return cols._format_native_types(**self._number_format) | ||
else: | ||
|
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.
is this TODO still needed?
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 don't know what it actually means here... :)