-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: DatetimeArray._from_sequence accepting bool dtype #32668
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 1 commit
1b81e42
cc4c7f9
8a2fa22
ecd66f2
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 |
---|---|---|
|
@@ -361,7 +361,18 @@ def _convert_listlike_datetimes( | |
# warn if passing timedelta64, raise for PeriodDtype | ||
# NB: this must come after unit transformation | ||
orig_arg = arg | ||
arg, _ = maybe_convert_dtype(arg, copy=False) | ||
try: | ||
arg, _ = maybe_convert_dtype(arg, copy=False) | ||
except TypeError: | ||
if errors == "coerce": | ||
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. actually do we have coverage for all of these paths? i seem to recall we using similar code elsewhere? 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. yes, we have tests in tests.tools.test_to_datetime that hit all of these cases 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. kk also maybe able to de-duplicate some of this code |
||
result = np.array(["NaT"], dtype="datetime64[ns]").repeat(len(arg)) | ||
return DatetimeIndex(result, name=name) | ||
elif errors == "ignore": | ||
from pandas import Index | ||
|
||
result = Index(arg, name=name) | ||
return result | ||
raise | ||
|
||
arg = ensure_object(arg) | ||
require_iso8601 = False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,11 +89,26 @@ def test_non_array_raises(self): | |
with pytest.raises(ValueError, match="list"): | ||
DatetimeArray([1, 2, 3]) | ||
|
||
def test_other_type_raises(self): | ||
def test_bool_dtype_raises(self): | ||
arr = np.array([1, 2, 3], dtype="bool") | ||
|
||
with pytest.raises( | ||
ValueError, match="The dtype of 'values' is incorrect.*bool" | ||
): | ||
DatetimeArray(np.array([1, 2, 3], dtype="bool")) | ||
DatetimeArray(arr) | ||
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. why is this a ValueError when DatetimeArray._from_sequence(arr) is a TypeError? Is is also worth considering making error messages consistent? 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. originally i made it type error, then changed for consistenty with... something, but i dont remember what. will try to figure that out and report bakc |
||
|
||
msg = r"dtype bool cannot be converted to datetime64\[ns\]" | ||
with pytest.raises(TypeError, match=msg): | ||
DatetimeArray._from_sequence(arr) | ||
|
||
with pytest.raises(TypeError, match=msg): | ||
sequence_to_dt64ns(arr) | ||
|
||
with pytest.raises(TypeError, match=msg): | ||
pd.DatetimeIndex(arr) | ||
|
||
with pytest.raises(TypeError, match=msg): | ||
pd.to_datetime(arr) | ||
|
||
def test_incorrect_dtype_raises(self): | ||
with pytest.raises(ValueError, match="Unexpected value for 'dtype'."): | ||
|
Uh oh!
There was an error while loading. Please reload this page.