-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN refactor core dtypes #37584
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
CLN refactor core dtypes #37584
Conversation
look ok. these may have broken things. |
Indeed - the refactoring - if len(types) == 0:
+ if not types: was wrong, as
Have fixed up and changed the annotation |
pandas/core/dtypes/cast.py
Outdated
@@ -1535,7 +1539,7 @@ def maybe_cast_to_datetime(value, dtype: DtypeObj, errors: str = "raise"): | |||
return value | |||
|
|||
|
|||
def find_common_type(types: List[DtypeObj]) -> DtypeObj: | |||
def find_common_type(types: Union[List[DtypeObj], Series]) -> DtypeObj: |
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.
where are we passing a Series? we shouldn't do this
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.
in pandas/tests/arrays/sparse/test_accessor.py::TestFrameAccessor::test_to_coo
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'll dig deeper at the weekend
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.
@jreback the problem is that when we do
df = pd.DataFrame({"A": [0, 1, 0], "B": [1, 0, 0]}, dtype="Sparse[int64, 0]")
result = df.sparse.to_coo()
then, in to_coo
from pandas/core/arrays/sparse/accessor.py, we have
dtype = find_common_type(self._parent.dtypes)
and so this is how we pass a Series (self._parent.dtypes
is a Series).
Is there a better way to fix this than
dtype = find_common_type(self._parent.dtypes.to_list())
?
can you merge master ping on green |
Green, barring (probably unrelated?) travis error:
|
@@ -329,7 +329,7 @@ def to_coo(self): | |||
import_optional_dependency("scipy") | |||
from scipy.sparse import coo_matrix | |||
|
|||
dtype = find_common_type(self._parent.dtypes) | |||
dtype = find_common_type(self._parent.dtypes.to_list()) |
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.
this is because find_commont_type
from pandas/core/dtypes/cast.py
requires a list
moving off 1.2 until ready |
Sure, no problem (though as far as I can tell, this is ready - anything else need changing?) |
I think it was fine, just want to make sure after merge |
sure, have merged |
pandas/core/dtypes/missing.py
Outdated
# tzawareness compat failure, see GH#28507 | ||
return False | ||
elif "boolean value of NA is ambiguous" in str(err): | ||
return False |
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 this is for coverage
… into refactor-core-dtypes
… into refactor-core-dtypes
thanks @MarcoGorelli |
Some refactorings found by Sourcery https://sourcery.ai/
I've removed the ones of the kind