Skip to content

Commit ea8791f

Browse files
authored
add assertion on type of df.values being numpy.ndarray + dtype='O' except for datetime64[ns]
1 parent e40c8e5 commit ea8791f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

pandas/tests/frame/test_dtypes.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -635,16 +635,19 @@ def test_values_with_tz_dtypes(self):
635635
["B", "B"],
636636
]:
637637
df_sub = df[col]
638+
arr = df_sub.values
638639

640+
self.assert(type(arr)==numpy.ndarray)
641+
639642
# array has the same dtype as dataframe only and only if
640-
# - dataframe has a single column
641-
# - or all columns are of type datetime64[ns]
643+
# - all columns are of type datetime64[ns]
642644

643645
# TODO: replace 2nd condition by 'all columns are of type datetime64[ns,same timezone]'
644646
# i.e. the test should succeed when replacing the condition be `if len(set(df_sub.dtypes.values))==1:`
645-
if len(df_sub.dtypes) == 1 or all(df_sub.dtypes.values=="<M8[ns]"):
646-
self.assertTrue(df_sub.values.dtype == df_sub.dtypes.values[0])
647+
# too complex before 2.0 as DatetimeTZBlock is single column
648+
if all(df_sub.dtypes.values=="<M8[ns]"):
649+
self.assertTrue(arr.dtype == df_sub.dtypes.values[0])
647650

648651
# otherwise, dtype is object
649652
else:
650-
self.assertTrue(df_sub.values.dtype == object)
653+
self.assertTrue(arr.dtype == object)

0 commit comments

Comments
 (0)