Skip to content

BUG: series construction from dict of Timedelta scalar doesn't work #38032

Closed
@arw2019

Description

@arw2019

Construction of Series from a dictionary of scalars sometimes fails:

Code Sample, a copy-pastable example

In [31]: import pandas as pd
    ...: import pandas._testing as tm
    ...: 
    ...: td = pd.Timedelta(nanoseconds=500)
    ...: ser = pd.Series({"a": td})
    ...: expected = pd.Series(td, index=["a"], dtype="timedelta64[ns]")
    ...: 
    ...: tm.assert_series_equal(ser, expected)
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-31-a9c6a6312101> in <module>
      6 expected = pd.Series(td, index=["a"], dtype="timedelta64[ns]")
      7 
----> 8 tm.assert_series_equal(ser, expected)

    [... skipping hidden 1 frame]

~/repos/pandas/pandas/_testing.py in assert_extension_array_equal(left, right, check_dtype, index_values, check_less_precise, check_exact, rtol, atol)
   1243         # Avoid slow object-dtype comparisons
   1244         # np.asarray for case where we have a np.MaskedArray
-> 1245         assert_numpy_array_equal(
   1246             np.asarray(left.asi8), np.asarray(right.asi8), index_values=index_values
   1247         )

    [... skipping hidden 1 frame]

~/repos/pandas/pandas/_testing.py in _raise(left, right, err_msg)
   1155             diff = diff * 100.0 / left.size
   1156             msg = f"{obj} values are different ({np.round(diff, 5)} %)"
-> 1157             raise_assert_detail(obj, msg, left, right, index_values=index_values)
   1158 
   1159         raise AssertionError(err_msg)

~/repos/pandas/pandas/_testing.py in raise_assert_detail(obj, message, left, right, diff, index_values)
   1085         msg += f"\n[diff]: {diff}"
   1086 
-> 1087     raise AssertionError(msg)
   1088 
   1089 

AssertionError: numpy array are different

numpy array values are different (100.0 %)
[index]: [a]
[left]:  [500]
[right]: [0]

Ran on 1.2 master

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsTimedeltaTimedelta data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions