@@ -69,6 +69,7 @@ class TestSeriesConstructors:
69
69
],
70
70
)
71
71
def test_empty_constructor (self , constructor , check_index_type ):
72
+ # TODO: share with frame test of the same name
72
73
with tm .assert_produces_warning (DeprecationWarning , check_stacklevel = False ):
73
74
expected = Series ()
74
75
result = constructor ()
@@ -310,6 +311,7 @@ def test_constructor_generator(self):
310
311
exp = Series (range (10 ))
311
312
tm .assert_series_equal (result , exp )
312
313
314
+ # same but with non-default index
313
315
gen = (i for i in range (10 ))
314
316
result = Series (gen , index = range (10 , 20 ))
315
317
exp .index = range (10 , 20 )
@@ -323,6 +325,7 @@ def test_constructor_map(self):
323
325
exp = Series (range (10 ))
324
326
tm .assert_series_equal (result , exp )
325
327
328
+ # same but with non-default index
326
329
m = map (lambda x : x , range (10 ))
327
330
result = Series (m , index = range (10 , 20 ))
328
331
exp .index = range (10 , 20 )
@@ -386,6 +389,7 @@ def test_constructor_categorical_with_coercion(self):
386
389
str (df .values )
387
390
str (df )
388
391
392
+ def test_constructor_categorical_with_coercion2 (self ):
389
393
# GH8623
390
394
x = DataFrame (
391
395
[[1 , "John P. Doe" ], [2 , "Jane Dove" ], [1 , "John P. Doe" ]],
@@ -747,6 +751,7 @@ def test_constructor_datelike_coercion(self):
747
751
assert s .iloc [1 ] == "NOV"
748
752
assert s .dtype == object
749
753
754
+ def test_constructor_datelike_coercion2 (self ):
750
755
# the dtype was being reset on the slicing and re-inferred to datetime
751
756
# even thought the blocks are mixed
752
757
belly = "216 3T19" .split ()
@@ -798,6 +803,7 @@ def test_constructor_dtype_datetime64(self):
798
803
assert isna (s [1 ])
799
804
assert s .dtype == "M8[ns]"
800
805
806
+ def test_constructor_dtype_datetime64_10 (self ):
801
807
# GH3416
802
808
dates = [
803
809
np .datetime64 (datetime (2013 , 1 , 1 )),
@@ -850,18 +856,21 @@ def test_constructor_dtype_datetime64(self):
850
856
expected = Series (dts .astype (np .int64 ))
851
857
tm .assert_series_equal (result , expected )
852
858
859
+ def test_constructor_dtype_datetime64_9 (self ):
853
860
# invalid dates can be help as object
854
861
result = Series ([datetime (2 , 1 , 1 )])
855
862
assert result [0 ] == datetime (2 , 1 , 1 , 0 , 0 )
856
863
857
864
result = Series ([datetime (3000 , 1 , 1 )])
858
865
assert result [0 ] == datetime (3000 , 1 , 1 , 0 , 0 )
859
866
867
+ def test_constructor_dtype_datetime64_8 (self ):
860
868
# don't mix types
861
869
result = Series ([Timestamp ("20130101" ), 1 ], index = ["a" , "b" ])
862
870
assert result ["a" ] == Timestamp ("20130101" )
863
871
assert result ["b" ] == 1
864
872
873
+ def test_constructor_dtype_datetime64_7 (self ):
865
874
# GH6529
866
875
# coerce datetime64 non-ns properly
867
876
dates = date_range ("01-Jan-2015" , "01-Dec-2015" , freq = "M" )
@@ -887,6 +896,7 @@ def test_constructor_dtype_datetime64(self):
887
896
tm .assert_numpy_array_equal (series1 .values , dates2 )
888
897
assert series1 .dtype == object
889
898
899
+ def test_constructor_dtype_datetime64_6 (self ):
890
900
# these will correctly infer a datetime
891
901
s = Series ([None , NaT , "2013-08-05 15:30:00.000001" ])
892
902
assert s .dtype == "datetime64[ns]"
@@ -897,6 +907,7 @@ def test_constructor_dtype_datetime64(self):
897
907
s = Series ([NaT , np .nan , "2013-08-05 15:30:00.000001" ])
898
908
assert s .dtype == "datetime64[ns]"
899
909
910
+ def test_constructor_dtype_datetime64_5 (self ):
900
911
# tz-aware (UTC and other tz's)
901
912
# GH 8411
902
913
dr = date_range ("20130101" , periods = 3 )
@@ -906,18 +917,21 @@ def test_constructor_dtype_datetime64(self):
906
917
dr = date_range ("20130101" , periods = 3 , tz = "US/Eastern" )
907
918
assert str (Series (dr ).iloc [0 ].tz ) == "US/Eastern"
908
919
920
+ def test_constructor_dtype_datetime64_4 (self ):
909
921
# non-convertible
910
922
s = Series ([1479596223000 , - 1479590 , NaT ])
911
923
assert s .dtype == "object"
912
924
assert s [2 ] is NaT
913
925
assert "NaT" in str (s )
914
926
927
+ def test_constructor_dtype_datetime64_3 (self ):
915
928
# if we passed a NaT it remains
916
929
s = Series ([datetime (2010 , 1 , 1 ), datetime (2 , 1 , 1 ), NaT ])
917
930
assert s .dtype == "object"
918
931
assert s [2 ] is NaT
919
932
assert "NaT" in str (s )
920
933
934
+ def test_constructor_dtype_datetime64_2 (self ):
921
935
# if we passed a nan it remains
922
936
s = Series ([datetime (2010 , 1 , 1 ), datetime (2 , 1 , 1 ), np .nan ])
923
937
assert s .dtype == "object"
@@ -980,6 +994,7 @@ def test_constructor_with_datetime_tz(self):
980
994
result = DatetimeIndex (s , freq = "infer" )
981
995
tm .assert_index_equal (result , dr )
982
996
997
+ def test_constructor_with_datetime_tz4 (self ):
983
998
# inference
984
999
s = Series (
985
1000
[
@@ -990,6 +1005,7 @@ def test_constructor_with_datetime_tz(self):
990
1005
assert s .dtype == "datetime64[ns, US/Pacific]"
991
1006
assert lib .infer_dtype (s , skipna = True ) == "datetime64"
992
1007
1008
+ def test_constructor_with_datetime_tz3 (self ):
993
1009
s = Series (
994
1010
[
995
1011
Timestamp ("2013-01-01 13:00:00-0800" , tz = "US/Pacific" ),
@@ -999,6 +1015,7 @@ def test_constructor_with_datetime_tz(self):
999
1015
assert s .dtype == "object"
1000
1016
assert lib .infer_dtype (s , skipna = True ) == "datetime"
1001
1017
1018
+ def test_constructor_with_datetime_tz2 (self ):
1002
1019
# with all NaT
1003
1020
s = Series (NaT , index = [0 , 1 ], dtype = "datetime64[ns, US/Eastern]" )
1004
1021
expected = Series (DatetimeIndex (["NaT" , "NaT" ], tz = "US/Eastern" ))
@@ -1231,14 +1248,6 @@ def test_constructor_dict_of_tuples(self):
1231
1248
expected = Series ([3 , 6 ], index = MultiIndex .from_tuples ([(1 , 2 ), (None , 5 )]))
1232
1249
tm .assert_series_equal (result , expected )
1233
1250
1234
- def test_constructor_set (self ):
1235
- values = {1 , 2 , 3 , 4 , 5 }
1236
- with pytest .raises (TypeError , match = "'set' type is unordered" ):
1237
- Series (values )
1238
- values = frozenset (values )
1239
- with pytest .raises (TypeError , match = "'frozenset' type is unordered" ):
1240
- Series (values )
1241
-
1242
1251
# https://github.com/pandas-dev/pandas/issues/22698
1243
1252
@pytest .mark .filterwarnings ("ignore:elementwise comparison:FutureWarning" )
1244
1253
def test_fromDict (self ):
0 commit comments