File tree 3 files changed +10
-12
lines changed
3 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 45
45
maybe_convert_platform ,
46
46
maybe_infer_to_datetimelike ,
47
47
maybe_upcast ,
48
- sanitize_to_nanoseconds ,
49
48
)
50
49
from pandas .core .dtypes .common import (
51
50
is_datetime64_ns_dtype ,
@@ -782,7 +781,9 @@ def _try_cast(
782
781
if is_ndarray :
783
782
arr = cast (np .ndarray , arr )
784
783
if arr .dtype != object :
785
- return sanitize_to_nanoseconds (arr , copy = copy )
784
+ if copy :
785
+ return arr .copy ()
786
+ return arr
786
787
787
788
out = maybe_infer_to_datetimelike (arr )
788
789
if out is arr and copy :
Original file line number Diff line number Diff line change @@ -1423,12 +1423,7 @@ def maybe_cast_to_datetime(
1423
1423
return astype_nansafe (value , dtype ) # type: ignore[arg-type]
1424
1424
1425
1425
elif isinstance (value , np .ndarray ):
1426
- if value .dtype .kind in ["M" , "m" ]:
1427
- # catch a datetime/timedelta that is not of ns variety
1428
- # and no coercion specified
1429
- value = sanitize_to_nanoseconds (value )
1430
-
1431
- elif value .dtype == _dtype_obj :
1426
+ if value .dtype == _dtype_obj :
1432
1427
value = maybe_infer_to_datetimelike (value )
1433
1428
1434
1429
elif isinstance (value , list ):
Original file line number Diff line number Diff line change 26
26
from pandas .util ._decorators import cache_readonly
27
27
from pandas .util ._exceptions import find_stack_level
28
28
29
- from pandas .core .dtypes .cast import sanitize_to_nanoseconds
30
29
from pandas .core .dtypes .common import (
31
30
is_categorical_dtype ,
32
31
is_list_like ,
@@ -558,9 +557,12 @@ def __init__(
558
557
raise AssertionError (errmsg )
559
558
560
559
if isinstance (self .grouping_vector , np .ndarray ):
561
- # if we have a date/time-like grouper, make sure that we have
562
- # Timestamps like
563
- self .grouping_vector = sanitize_to_nanoseconds (self .grouping_vector )
560
+ if self .grouping_vector .dtype .kind in ["m" , "M" ]:
561
+ # if we have a date/time-like grouper, make sure that we have
562
+ # Timestamps like
563
+ # TODO 2022-10-08 we only have one test that gets here and
564
+ # values are already in nanoseconds in that case.
565
+ self .grouping_vector = Series (self .grouping_vector ).to_numpy ()
564
566
565
567
def __repr__ (self ) -> str :
566
568
return f"Grouping({ self .name } )"
You can’t perform that action at this time.
0 commit comments