4
4
"""
5
5
6
6
import copy
7
- from datetime import date , datetime
7
+ from datetime import date
8
8
import itertools
9
9
import os
10
10
import re
11
- import time
12
11
from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple , Type , Union
13
12
import warnings
14
13
43
42
TimedeltaIndex ,
44
43
concat ,
45
44
isna ,
46
- to_datetime ,
47
45
)
48
46
from pandas .core .arrays .categorical import Categorical
49
47
from pandas .core .arrays .sparse import BlockIndex , IntIndex
@@ -2137,6 +2135,7 @@ def set_kind(self):
2137
2135
elif dtype .startswith ("int" ) or dtype .startswith ("uint" ):
2138
2136
self .kind = "integer"
2139
2137
elif dtype .startswith ("date" ):
2138
+ # in tests this is always "datetime64"
2140
2139
self .kind = "datetime"
2141
2140
elif dtype .startswith ("timedelta" ):
2142
2141
self .kind = "timedelta"
@@ -2182,8 +2181,8 @@ def set_atom(
2182
2181
if inferred_type == "date" :
2183
2182
raise TypeError ("[date] is not implemented as a table column" )
2184
2183
elif inferred_type == "datetime" :
2185
- # after 8260
2186
- # this only would be hit for a mutli -timezone dtype
2184
+ # after GH# 8260
2185
+ # this only would be hit for a multi -timezone dtype
2187
2186
# which is an error
2188
2187
2189
2188
raise TypeError (
@@ -2406,10 +2405,6 @@ def convert(self, values, nan_rep, encoding, errors, start=None, stop=None):
2406
2405
self .data = np .asarray (
2407
2406
[date .fromtimestamp (v ) for v in self .data ], dtype = object
2408
2407
)
2409
- elif dtype == "datetime" :
2410
- self .data = np .asarray (
2411
- [datetime .fromtimestamp (v ) for v in self .data ], dtype = object
2412
- )
2413
2408
2414
2409
elif meta == "category" :
2415
2410
@@ -2920,7 +2915,7 @@ def read_index_node(
2920
2915
# created by python3
2921
2916
kwargs ["tz" ] = node ._v_attrs ["tz" ]
2922
2917
2923
- if kind in ( "date" , "datetime" ) :
2918
+ if kind == "date" :
2924
2919
index = factory (
2925
2920
_unconvert_index (
2926
2921
data , kind , encoding = self .encoding , errors = self .errors
@@ -4619,39 +4614,12 @@ def _convert_index(name: str, index, encoding=None, errors="strict", format_type
4619
4614
raise TypeError ("MultiIndex not supported here!" )
4620
4615
4621
4616
inferred_type = lib .infer_dtype (index , skipna = False )
4617
+ # we wont get inferred_type of "datetime64" or "timedelta64" as these
4618
+ # would go through the DatetimeIndex/TimedeltaIndex paths above
4622
4619
4623
4620
values = np .asarray (index )
4624
4621
4625
- if inferred_type == "datetime64" :
4626
- converted = values .view ("i8" )
4627
- return IndexCol (
4628
- name ,
4629
- converted ,
4630
- "datetime64" ,
4631
- _tables ().Int64Col (),
4632
- freq = getattr (index , "freq" , None ),
4633
- tz = getattr (index , "tz" , None ),
4634
- index_name = index_name ,
4635
- )
4636
- elif inferred_type == "timedelta64" :
4637
- converted = values .view ("i8" )
4638
- return IndexCol (
4639
- name ,
4640
- converted ,
4641
- "timedelta64" ,
4642
- _tables ().Int64Col (),
4643
- freq = getattr (index , "freq" , None ),
4644
- index_name = index_name ,
4645
- )
4646
- elif inferred_type == "datetime" :
4647
- converted = np .asarray (
4648
- [(time .mktime (v .timetuple ()) + v .microsecond / 1e6 ) for v in values ],
4649
- dtype = np .float64 ,
4650
- )
4651
- return IndexCol (
4652
- name , converted , "datetime" , _tables ().Time64Col (), index_name = index_name
4653
- )
4654
- elif inferred_type == "date" :
4622
+ if inferred_type == "date" :
4655
4623
converted = np .asarray ([v .toordinal () for v in values ], dtype = np .int32 )
4656
4624
return IndexCol (
4657
4625
name , converted , "date" , _tables ().Time32Col (), index_name = index_name ,
@@ -4670,19 +4638,6 @@ def _convert_index(name: str, index, encoding=None, errors="strict", format_type
4670
4638
itemsize = itemsize ,
4671
4639
index_name = index_name ,
4672
4640
)
4673
- elif inferred_type == "unicode" :
4674
- if format_type == "fixed" :
4675
- atom = _tables ().ObjectAtom ()
4676
- return IndexCol (
4677
- name ,
4678
- np .asarray (values , dtype = "O" ),
4679
- "object" ,
4680
- atom ,
4681
- index_name = index_name ,
4682
- )
4683
- raise TypeError (
4684
- f"[unicode] is not supported as a in index type for [{ format_type } ] formats"
4685
- )
4686
4641
4687
4642
elif inferred_type == "integer" :
4688
4643
# take a guess for now, hope the values fit
@@ -4703,7 +4658,7 @@ def _convert_index(name: str, index, encoding=None, errors="strict", format_type
4703
4658
atom ,
4704
4659
index_name = index_name ,
4705
4660
)
4706
- else : # pragma: no cover
4661
+ else :
4707
4662
atom = _tables ().ObjectAtom ()
4708
4663
return IndexCol (
4709
4664
name , np .asarray (values , dtype = "O" ), "object" , atom , index_name = index_name ,
@@ -4716,8 +4671,6 @@ def _unconvert_index(data, kind, encoding=None, errors="strict"):
4716
4671
index = DatetimeIndex (data )
4717
4672
elif kind == "timedelta64" :
4718
4673
index = TimedeltaIndex (data )
4719
- elif kind == "datetime" :
4720
- index = np .asarray ([datetime .fromtimestamp (v ) for v in data ], dtype = object )
4721
4674
elif kind == "date" :
4722
4675
try :
4723
4676
index = np .asarray ([date .fromordinal (v ) for v in data ], dtype = object )
@@ -4819,16 +4772,14 @@ def _maybe_convert(values: np.ndarray, val_kind, encoding, errors):
4819
4772
def _get_converter (kind : str , encoding , errors ):
4820
4773
if kind == "datetime64" :
4821
4774
return lambda x : np .asarray (x , dtype = "M8[ns]" )
4822
- elif kind == "datetime" :
4823
- return lambda x : to_datetime (x , cache = True ).to_pydatetime ()
4824
4775
elif kind == "string" :
4825
4776
return lambda x : _unconvert_string_array (x , encoding = encoding , errors = errors )
4826
4777
else : # pragma: no cover
4827
4778
raise ValueError (f"invalid kind { kind } " )
4828
4779
4829
4780
4830
4781
def _need_convert (kind ) -> bool :
4831
- if kind in ("datetime" , " datetime64" , "string" ):
4782
+ if kind in ("datetime64" , "string" ):
4832
4783
return True
4833
4784
return False
4834
4785
0 commit comments