-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Typeinterval part1 #46080
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
Typeinterval part1 #46080
Changes from 11 commits
9e57d6d
2abbc57
99158b1
0f4130d
24ecfe2
64f00d5
1ee6e00
34dc181
a547800
3a3bfea
5edf5c9
7c4cd5c
649ef07
9769356
40be56f
4fcf523
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import numpy as np | ||
|
||
from pandas._libs.tslibs.nattype import NaTType | ||
Dr-Irv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from pandas._typing import ( | ||
FilePath, | ||
ReadBuffer, | ||
|
@@ -81,7 +82,9 @@ def get_sheet_by_name(self, name: str): | |
self.close() | ||
raise ValueError(f"sheet {name} not found") | ||
|
||
def get_sheet_data(self, sheet, convert_float: bool) -> list[list[Scalar]]: | ||
def get_sheet_data( | ||
self, sheet, convert_float: bool | ||
) -> list[list[Scalar | NaTType]]: | ||
""" | ||
Parse an ODF Table into a list of lists | ||
""" | ||
|
@@ -99,12 +102,12 @@ def get_sheet_data(self, sheet, convert_float: bool) -> list[list[Scalar]]: | |
empty_rows = 0 | ||
max_row_len = 0 | ||
|
||
table: list[list[Scalar]] = [] | ||
table: list[list[Scalar | NaTType]] = [] | ||
|
||
for sheet_row in sheet_rows: | ||
sheet_cells = [x for x in sheet_row.childNodes if x.qname in cell_names] | ||
empty_cells = 0 | ||
table_row: list[Scalar] = [] | ||
table_row: list[Scalar | NaTType] = [] | ||
|
||
for sheet_cell in sheet_cells: | ||
if sheet_cell.qname == table_cell_name: | ||
|
@@ -167,7 +170,7 @@ def _is_empty_row(self, row) -> bool: | |
|
||
return True | ||
|
||
def _get_cell_value(self, cell, convert_float: bool) -> Scalar: | ||
def _get_cell_value(self, cell, convert_float: bool) -> Scalar | NaTType: | ||
from odf.namespaces import OFFICENS | ||
|
||
if str(cell) == "#N/A": | ||
|
@@ -200,9 +203,12 @@ def _get_cell_value(self, cell, convert_float: bool) -> Scalar: | |
cell_value = cell.attributes.get((OFFICENS, "date-value")) | ||
return pd.to_datetime(cell_value) | ||
elif cell_type == "time": | ||
stamp = pd.to_datetime(str(cell)) | ||
# error: Item "str" of "Union[float, str, NaTType]" has no attribute "time" | ||
return stamp.time() # type: ignore[union-attr] | ||
stamp: pd.Timestamp | NaTType = pd.to_datetime(str(cell)) | ||
if not isinstance(stamp, NaTType): | ||
return stamp.time() | ||
else: | ||
self.close() | ||
raise ValueError(f"Unrecognized time {str(cell)}") | ||
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 changing code in a typing PR, I have some questions... does it change behavior? 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. Given that it is a time, the other solution is to just do a |
||
else: | ||
self.close() | ||
raise ValueError(f"Unrecognized type {cell_type}") | ||
|
Uh oh!
There was an error while loading. Please reload this page.