Skip to content

Commit cf3cdca

Browse files
authored
add test_values_with_tz_dtypes related to pandas-dev#14052
With respect to the discussion in pandas-dev#14052, the case ["B","B"] (multiple columns of datetime64[ns, tz] with a common tz) could be improved to return an array with the same dtype as the dataframe
1 parent fe15466 commit cf3cdca

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

pandas/tests/frame/test_dtypes.py

+23
Original file line numberDiff line numberDiff line change
@@ -622,3 +622,26 @@ def test_astype_str(self):
622622
'NaT NaT' in result)
623623
self.assertTrue('2 2013-01-03 2013-01-03 00:00:00-05:00 '
624624
'2013-01-03 00:00:00+01:00' in result)
625+
626+
def test_values_with_tz_dtypes(self):
627+
df = DataFrame({'A': date_range('20130101', periods=3),
628+
'B': date_range('20130101', periods=3, tz='US/Eastern'),
629+
})
630+
for col in [
631+
["A"],
632+
["A", "A"],
633+
["A", "B"],
634+
["B"],
635+
["B", "B"],
636+
]:
637+
df_sub = df[col]
638+
639+
# 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]
642+
if len(df_sub.dtypes) == 1 or all(df_sub.dtypes.values=="<M8[ns]"):
643+
self.assertTrue(df_sub.values.dtype == df_sub.dtypes.values[0])
644+
645+
# otherwise, dtype is object
646+
else:
647+
self.assertTrue(df_sub.values.dtype == object)

0 commit comments

Comments
 (0)