Skip to content

TYP: changed variable cat_array to cat_array_list in dtypes.py #44373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0fd3c66
changed variable hashed to combined_hashed in dtype.py
nickleus27 Nov 8, 2021
c3e784f
pre-commit changes
nickleus27 Nov 9, 2021
5404817
changed cat_array assignment to cat_array_list
nickleus27 Nov 9, 2021
dfd154d
Merge branch 'master' into assign_err
nickleus27 Nov 9, 2021
3cefbcc
changed arr to arr_lst
nickleus27 Nov 14, 2021
80bd1f1
Revert "changed arr to arr_lst"
nickleus27 Nov 14, 2021
1601c53
changed arr to arr_lst
nickleus27 Nov 14, 2021
2338a22
CLN: split giant dt accessor tests (#44355)
jbrockmendel Nov 10, 2021
2d9bddf
REF: re-remove _putmask_preserve (#44346)
jbrockmendel Nov 10, 2021
c3cefa7
TST: enable 2D tests for Categorical (#44206)
jbrockmendel Nov 10, 2021
b0c1671
TST/COMPAT: update csv test to infer time with pyarrow>=6.0 (#44381)
jorisvandenbossche Nov 10, 2021
5694f78
TST: Make tests for groupby median/mean more strict on dtype (#44374)
rhshadrach Nov 11, 2021
fded332
TST: make get_upcast_box more flexible (#44385)
jbrockmendel Nov 11, 2021
5808135
CI: Use conda-forge to create Python 3.10 env (#44388)
lithomas1 Nov 11, 2021
5a9d584
CLN: misplaced indexing tests (#44375)
jbrockmendel Nov 11, 2021
ae4a888
BUG: PeriodIndex[B].to_timestamp inferring "D" instead of "B". (#44105)
jbrockmendel Nov 11, 2021
c4316b5
Fix header options (#44391)
LunarLanding Nov 11, 2021
885a1c4
ENH: implement EA._putmask (#44387)
jbrockmendel Nov 11, 2021
9db50bf
collect partial tests (#44372)
jbrockmendel Nov 11, 2021
e4ddd2d
CLN: split/fixturize to_datetime tests (#44367)
jbrockmendel Nov 11, 2021
a23f5df
TST: use custom parametrization for consistency in base extension arr…
jorisvandenbossche Nov 11, 2021
7a31ca8
TST: parametrize arithmetic tests (#44395)
jbrockmendel Nov 11, 2021
9e8ab56
REF/TST: collect index tests (#44377)
jbrockmendel Nov 11, 2021
eca9f6c
Fixed regression in Series.duplicated for categorical dtype with bool…
phofl Nov 12, 2021
dc61547
CLN: Refactor extract multiindex header call (#44399)
phofl Nov 12, 2021
66147c9
BUG: DataFrame.stack with EA columns (#44401)
jbrockmendel Nov 12, 2021
a0a76a1
ENH: Use find_stack_level in pandas.core (#44358)
rhshadrach Nov 12, 2021
085acb6
TST: Add nulls fixture to duplicates categorical na test (#44407)
phofl Nov 12, 2021
a0b00b8
[BUG] don't mangle null-objects in value_counts (#42743)
realead Nov 12, 2021
0010c6d
BUG: frame.loc[2:, 'z'] not setting inplace when multi-block (#44345)
jbrockmendel Nov 13, 2021
f1f7a75
DataFrame.convert_dtypes doesn't preserve subclasses (#44249)
m-richards Nov 13, 2021
b948260
ENH: Use find_stack_level (#44416)
rhshadrach Nov 13, 2021
cda4544
TST: de-duplicate assert_slics_equivalent (#44415)
jbrockmendel Nov 13, 2021
f537c13
DOC: Add how=cross description to join (#44418)
phofl Nov 13, 2021
a5700de
DOC: whatsnew for the improvement to warning messages (#44419)
rhshadrach Nov 13, 2021
6d34855
BUG: handle NaNs in FloatingArray.equals (#44390)
jbrockmendel Nov 13, 2021
c456969
Fix FloatingArray.equals on older numpy (#44432)
jbrockmendel Nov 13, 2021
7483ee9
BUG: DataFrame with mismatched NA value and dtype (#44428)
jbrockmendel Nov 14, 2021
25401fc
TST: collect/share Index tests (#44413)
jbrockmendel Nov 14, 2021
07261dd
disable xfail (#44436)
jbrockmendel Nov 14, 2021
1a4a689
REF: simplify putmask_smart (#44435)
jbrockmendel Nov 14, 2021
4f05236
ENH: Use stacklevel in warnings (#44439)
rhshadrach Nov 14, 2021
25b1224
TST: FIXMES in DataFrame.quantile tests (#44437)
jbrockmendel Nov 14, 2021
0e442be
BLD: Exclude CPT data files (#44441)
lithomas1 Nov 14, 2021
53ca6eb
BUG: DataFrame.astype(series) with duplicate columns (#44417)
jbrockmendel Nov 14, 2021
a3c964d
DOC: Some minor doc cleanups (#44440)
phofl Nov 14, 2021
effe737
BUG: read_csv raising if parse_dates is used with MultiIndex columns …
phofl Nov 14, 2021
d4106aa
Doc: Clean obj.empty docs to describe Series/DataFrame (#44430)
phofl Nov 14, 2021
72e6097
BUG: .get_indexer_non_unique() must return an array of ints (#44084) …
johannes-mueller Nov 14, 2021
acffba2
BUG: closes #44312: fixes unwanted TypeError when a missing metadata …
qdbp Nov 14, 2021
01a6f4b
DOC: df.to_html documentation incorrectly contains min_rows optional …
loicdiridollou Nov 14, 2021
5307b18
[BUG] Fix DataFrameGroupBy.boxplot with subplots=False fails for obje…
brendandrury Nov 14, 2021
564c857
ENH: Support timespec argument in Timestamp.isoformat() (#44397)
swt2c Nov 14, 2021
4689a28
DEPR: PeriodIndex.astype(dt64) (#44398)
jbrockmendel Nov 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/sdist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: pandas-sdist
channels: conda-forge
python-version: '${{ matrix.python-version }}'

- name: Install pandas from sdist
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ global-exclude *.xlsb
global-exclude *.xlsm
global-exclude *.xlsx
global-exclude *.xpt
global-exclude *.cpt
global-exclude *.xz
global-exclude *.zip
global-exclude *~
Expand Down
24 changes: 24 additions & 0 deletions asv_bench/benchmarks/series_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ def time_value_counts(self, N, dtype):
self.s.value_counts()


class ValueCountsObjectDropNAFalse:

params = [10 ** 3, 10 ** 4, 10 ** 5]
param_names = ["N"]

def setup(self, N):
self.s = Series(np.random.randint(0, N, size=10 * N)).astype("object")

def time_value_counts(self, N):
self.s.value_counts(dropna=False)


class Mode:

params = [[10 ** 3, 10 ** 4, 10 ** 5], ["int", "uint", "float", "object"]]
Expand All @@ -164,6 +176,18 @@ def time_mode(self, N, dtype):
self.s.mode()


class ModeObjectDropNAFalse:

params = [10 ** 3, 10 ** 4, 10 ** 5]
param_names = ["N"]

def setup(self, N):
self.s = Series(np.random.randint(0, N, size=10 * N)).astype("object")

def time_mode(self, N):
self.s.mode(dropna=False)


class Dir:
def setup(self):
self.s = Series(index=tm.makeStringIndex(10000))
Expand Down
9 changes: 5 additions & 4 deletions doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ header : int or list of ints, default ``'infer'``
names : array-like, default ``None``
List of column names to use. If file contains no header row, then you should
explicitly pass ``header=None``. Duplicates in this list are not allowed.
index_col : int, str, sequence of int / str, or False, default ``None``
index_col : int, str, sequence of int / str, or False, optional, default ``None``
Column(s) to use as the row labels of the ``DataFrame``, either given as
string name or column index. If a sequence of int / str is given, a
MultiIndex is used.
Expand All @@ -120,7 +120,8 @@ usecols : list-like or callable, default ``None``
Return a subset of the columns. If list-like, all elements must either
be positional (i.e. integer indices into the document columns) or strings
that correspond to column names provided either by the user in ``names`` or
inferred from the document header row(s). For example, a valid list-like
inferred from the document header row(s). If ``names`` are given, the document
header row(s) are not taken into account. For example, a valid list-like
``usecols`` parameter would be ``[0, 1, 2]`` or ``['foo', 'bar', 'baz']``.

Element order is ignored, so ``usecols=[0, 1]`` is the same as ``[1, 0]``. To
Expand Down Expand Up @@ -348,7 +349,7 @@ dialect : str or :class:`python:csv.Dialect` instance, default ``None``
Error handling
++++++++++++++

error_bad_lines : boolean, default ``None``
error_bad_lines : boolean, optional, default ``None``
Lines with too many fields (e.g. a csv line with too many commas) will by
default cause an exception to be raised, and no ``DataFrame`` will be
returned. If ``False``, then these "bad lines" will dropped from the
Expand All @@ -358,7 +359,7 @@ error_bad_lines : boolean, default ``None``
.. deprecated:: 1.3.0
The ``on_bad_lines`` parameter should be used instead to specify behavior upon
encountering a bad line instead.
warn_bad_lines : boolean, default ``None``
warn_bad_lines : boolean, optional, default ``None``
If error_bad_lines is ``False``, and warn_bad_lines is ``True``, a warning for
each "bad line" will be output.

Expand Down
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed regression in :meth:`Series.equals` when comparing floats with dtype object to None (:issue:`44190`)
- Fixed performance regression in :func:`read_csv` (:issue:`44106`)
- Fixed regression in :meth:`Series.duplicated` and :meth:`Series.drop_duplicates` when Series has :class:`Categorical` dtype with boolean categories (:issue:`44351`)
-

.. ---------------------------------------------------------------------------
Expand Down
74 changes: 72 additions & 2 deletions doc/source/whatsnew/v1.4.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,31 @@ including other versions of pandas.
Enhancements
~~~~~~~~~~~~

.. _whatsnew_140.enhancements.warning_lineno:

Improved warning messages
^^^^^^^^^^^^^^^^^^^^^^^^^

Previously, warning messages may have pointed to lines within the pandas library. Running the script ``setting_with_copy_warning.py``

.. code-block:: python

import pandas as pd

df = pd.DataFrame({'a': [1, 2, 3]})
df[:2].loc[:, 'a'] = 5

with pandas 1.3 resulted in::

.../site-packages/pandas/core/indexing.py:1951: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.

This made it difficult to determine where the warning was being generated from. Now pandas will inspect the call stack, reporting the first line outside of the pandas library that gave rise to the warning. The output of the above script is now::

setting_with_copy_warning.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.


.. _whatsnew_140.enhancements.numeric_index:

More flexible numeric dtypes for indexes
Expand Down Expand Up @@ -184,6 +209,7 @@ Other enhancements
- :meth:`DataFrame.dropna` now accepts a single label as ``subset`` along with array-like (:issue:`41021`)
- :meth:`read_excel` now accepts a ``decimal`` argument that allow the user to specify the decimal point when parsing string columns to numeric (:issue:`14403`)
- :meth:`.GroupBy.mean` now supports `Numba <http://numba.pydata.org/>`_ execution with the ``engine`` keyword (:issue:`43731`)
- :meth:`Timestamp.isoformat`, now handles the ``timespec`` argument from the base :class:``datetime`` class (:issue:`26131`)

.. ---------------------------------------------------------------------------

Expand Down Expand Up @@ -240,6 +266,38 @@ Now the float-dtype is respected. Since the common dtype for these DataFrames is

*New behavior*:

.. ipython:: python

res

.. _whatsnew_140.notable_bug_fixes.value_counts_and_mode_do_not_coerse_to_nan:

Null-values are no longer coerced to NaN-value in value_counts and mode
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:meth:`Series.value_counts` and :meth:`Series.mode` no longer coerce ``None``, ``NaT`` and other null-values to a NaN-value for ``np.object``-dtype. This behavior is now consistent with ``unique``, ``isin`` and others (:issue:`42688`).

.. ipython:: python

s = pd.Series([True, None, pd.NaT, None, pd.NaT, None])
res = s.value_counts(dropna=False)

Previously, all null-values were replaced by a NaN-value.

*Previous behavior*:

.. code-block:: ipython

In [3]: res
Out[3]:
NaN 5
True 1
dtype: int64

Now null-values are no longer mangled.

*New behavior*:

.. ipython:: python

res
Expand Down Expand Up @@ -400,6 +458,8 @@ Other Deprecations
- Deprecated casting behavior when setting timezone-aware value(s) into a timezone-aware :class:`Series` or :class:`DataFrame` column when the timezones do not match. Previously this cast to object dtype. In a future version, the values being inserted will be converted to the series or column's existing timezone (:issue:`37605`)
- Deprecated casting behavior when passing an item with mismatched-timezone to :meth:`DatetimeIndex.insert`, :meth:`DatetimeIndex.putmask`, :meth:`DatetimeIndex.where` :meth:`DatetimeIndex.fillna`, :meth:`Series.mask`, :meth:`Series.where`, :meth:`Series.fillna`, :meth:`Series.shift`, :meth:`Series.replace`, :meth:`Series.reindex` (and :class:`DataFrame` column analogues). In the past this has cast to object dtype. In a future version, these will cast the passed item to the index or series's timezone (:issue:`37605`)
- Deprecated the 'errors' keyword argument in :meth:`Series.where`, :meth:`DataFrame.where`, :meth:`Series.mask`, and meth:`DataFrame.mask`; in a future version the argument will be removed (:issue:`44294`)
- Deprecated :meth:`PeriodIndex.astype` to ``datetime64[ns]`` or ``DatetimeTZDtype``, use ``obj.to_timestamp(how).tz_localize(dtype.tz)`` instead (:issue:`44398`)
-

.. ---------------------------------------------------------------------------

Expand Down Expand Up @@ -506,6 +566,7 @@ Conversion
- Bug in :class:`Series` constructor returning 0 for missing values with dtype ``int64`` and ``False`` for dtype ``bool`` (:issue:`43017`, :issue:`43018`)
- Bug in :class:`IntegerDtype` not allowing coercion from string dtype (:issue:`25472`)
- Bug in :func:`to_datetime` with ``arg:xr.DataArray`` and ``unit="ns"`` specified raises TypeError (:issue:`44053`)
- Bug in :meth:`DataFrame.convert_dtypes` not returning the correct type when a subclass does not overload :meth:`_constructor_sliced` (:issue:`43201`)
-

Strings
Expand All @@ -515,7 +576,7 @@ Strings

Interval
^^^^^^^^
-
- Bug in :meth:`IntervalIndex.get_indexer_non_unique` returning boolean mask instead of array of integers for a non unique and non monotonic index (:issue:`44084`)
-

Indexing
Expand Down Expand Up @@ -543,12 +604,14 @@ Indexing
- Bug when setting string-backed :class:`Categorical` values that can be parsed to datetimes into a :class:`DatetimeArray` or :class:`Series` or :class:`DataFrame` column backed by :class:`DatetimeArray` failing to parse these strings (:issue:`44236`)
- Bug in :meth:`Series.__setitem__` with an integer dtype other than ``int64`` setting with a ``range`` object unnecessarily upcasting to ``int64`` (:issue:`44261`)
- Bug in :meth:`Series.__setitem__` with a boolean mask indexer setting a listlike value of length 1 incorrectly broadcasting that value (:issue:`44265`)
- Bug in :meth:`DataFrame.loc.__setitem__` and :meth:`DataFrame.iloc.__setitem__` with mixed dtypes sometimes failing to operate in-place (:issue:`44345`)
-

Missing
^^^^^^^
- Bug in :meth:`DataFrame.fillna` with limit and no method ignores axis='columns' or ``axis = 1`` (:issue:`40989`)
- Bug in :meth:`DataFrame.fillna` not replacing missing values when using a dict-like ``value`` and duplicate column names (:issue:`43476`)
- Bug in constructing a :class:`DataFrame` with a dictionary ``np.datetime64`` as a value and ``dtype='timedelta64[ns]'``, or vice-versa, incorrectly casting instead of raising (:issue:`??`)
-

MultiIndex
Expand All @@ -572,18 +635,21 @@ I/O
- Bug in :func:`read_csv`, changed exception class when expecting a file path name or file-like object from ``OSError`` to ``TypeError`` (:issue:`43366`)
- Bug in :func:`read_json` not handling non-numpy dtypes correctly (especially ``category``) (:issue:`21892`, :issue:`33205`)
- Bug in :func:`json_normalize` where multi-character ``sep`` parameter is incorrectly prefixed to every key (:issue:`43831`)
- Bug in :func:`json_normalize` where reading data with missing multi-level metadata would not respect errors="ignore" (:issue:`44312`)
- Bug in :func:`read_csv` with :code:`float_precision="round_trip"` which did not skip initial/trailing whitespace (:issue:`43713`)
- Bug in dumping/loading a :class:`DataFrame` with ``yaml.dump(frame)`` (:issue:`42748`)
- Bug in :func:`read_csv` raising ``ValueError`` when ``parse_dates`` was used with ``MultiIndex`` columns (:issue:`8991`)
-

Period
^^^^^^
- Bug in adding a :class:`Period` object to a ``np.timedelta64`` object incorrectly raising ``TypeError`` (:issue:`44182`)
- Bug in :meth:`PeriodIndex.to_timestamp` when the index has ``freq="B"`` inferring ``freq="D"`` for its result instead of ``freq="B"`` (:issue:`44105`)
-

Plotting
^^^^^^^^
-
- When given non-numeric data, :meth:`DataFrame.boxplot` now raises a ``ValueError`` rather than a cryptic ``KeyError`` or ``ZeroDivsionError``, in line with other plotting functions like :meth:`DataFrame.hist`. (:issue:`43480`)
-

Groupby/resample/rolling
Expand Down Expand Up @@ -622,6 +688,8 @@ Reshaping
- Bug in :func:`crosstab` would fail when inputs are lists or tuples (:issue:`44076`)
- Bug in :meth:`DataFrame.append` failing to retain ``index.name`` when appending a list of :class:`Series` objects (:issue:`44109`)
- Fixed metadata propagation in :meth:`Dataframe.apply` method, consequently fixing the same issue for :meth:`Dataframe.transform`, :meth:`Dataframe.nunique` and :meth:`Dataframe.mode` (:issue:`28283`)
- Bug in :meth:`DataFrame.stack` with ``ExtensionDtype`` columns incorrectly raising (:issue:`43561`)
-

Sparse
^^^^^^
Expand Down Expand Up @@ -652,11 +720,13 @@ Styler

Other
^^^^^
- Bug in :meth:`DataFrame.astype` with non-unique columns and a :class:`Series` ``dtype`` argument (:issue:`44417`)
- Bug in :meth:`CustomBusinessMonthBegin.__add__` (:meth:`CustomBusinessMonthEnd.__add__`) not applying the extra ``offset`` parameter when beginning (end) of the target month is already a business day (:issue:`41356`)
- Bug in :meth:`RangeIndex.union` with another ``RangeIndex`` with matching (even) ``step`` and starts differing by strictly less than ``step / 2`` (:issue:`44019`)
- Bug in :meth:`RangeIndex.difference` with ``sort=None`` and ``step<0`` failing to sort (:issue:`44085`)
- Bug in :meth:`Series.to_frame` and :meth:`Index.to_frame` ignoring the ``name`` argument when ``name=None`` is explicitly passed (:issue:`44212`)
- Bug in :meth:`Series.replace` and :meth:`DataFrame.replace` with ``value=None`` and ExtensionDtypes (:issue:`44270`)
- Bug in :meth:`FloatingArray.equals` failing to consider two arrays equal if they contain ``np.nan`` values (:issue:`44382`)
-

.. ***DO NOT USE THIS SECTION***
Expand Down
9 changes: 2 additions & 7 deletions pandas/_libs/hashtable_func_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dtypes = [('Complex128', 'complex128', 'complex128',
@cython.wraparound(False)
@cython.boundscheck(False)
{{if dtype == 'object'}}
cdef value_count_{{dtype}}(ndarray[{{dtype}}] values, bint dropna, navalue=np.NaN):
cdef value_count_{{dtype}}(ndarray[{{dtype}}] values, bint dropna):
{{else}}
cdef value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna):
{{endif}}
Expand All @@ -42,7 +42,6 @@ cdef value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna):

# Don't use Py_ssize_t, since table.n_buckets is unsigned
khiter_t k
bint is_null

{{c_type}} val

Expand All @@ -61,11 +60,7 @@ cdef value_count_{{dtype}}(const {{dtype}}_t[:] values, bint dropna):

for i in range(n):
val = values[i]
is_null = checknull(val)
if not is_null or not dropna:
# all nas become the same representative:
if is_null:
val = navalue
if not dropna or not checknull(val):
k = kh_get_{{ttype}}(table, <PyObject*>val)
if k != table.n_buckets:
table.vals[k] += 1
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ cdef class _NaT(datetime):
def __str__(self) -> str:
return "NaT"

def isoformat(self, sep="T") -> str:
def isoformat(self, sep: str = "T", timespec: str = "auto") -> str:
# This allows Timestamp(ts.isoformat()) to always correctly roundtrip.
return "NaT"

Expand Down
48 changes: 41 additions & 7 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -737,20 +737,54 @@ cdef class _Timestamp(ABCTimestamp):
# -----------------------------------------------------------------
# Rendering Methods

def isoformat(self, sep: str = "T") -> str:
base = super(_Timestamp, self).isoformat(sep=sep)
if self.nanosecond == 0:
def isoformat(self, sep: str = "T", timespec: str = "auto") -> str:
"""
Return the time formatted according to ISO.

The full format looks like 'YYYY-MM-DD HH:MM:SS.mmmmmmnnn'.
By default, the fractional part is omitted if self.microsecond == 0
and self.nanosecond == 0.

If self.tzinfo is not None, the UTC offset is also attached, giving
giving a full format of 'YYYY-MM-DD HH:MM:SS.mmmmmmnnn+HH:MM'.

Parameters
----------
sep : str, default 'T'
String used as the separator between the date and time.

timespec : str, default 'auto'
Specifies the number of additional terms of the time to include.
The valid values are 'auto', 'hours', 'minutes', 'seconds',
'milliseconds', 'microseconds', and 'nanoseconds'.

Returns
-------
str

Examples
--------
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
>>> ts.isoformat()
'2020-03-14T15:32:52.192548651'
>>> ts.isoformat(timespec='microseconds')
'2020-03-14T15:32:52.192548'
"""
base_ts = "microseconds" if timespec == "nanoseconds" else timespec
base = super(_Timestamp, self).isoformat(sep=sep, timespec=base_ts)
if self.nanosecond == 0 and timespec != "nanoseconds":
return base

if self.tzinfo is not None:
base1, base2 = base[:-6], base[-6:]
else:
base1, base2 = base, ""

if self.microsecond != 0:
base1 += f"{self.nanosecond:03d}"
else:
base1 += f".{self.nanosecond:09d}"
if timespec == "nanoseconds" or (timespec == "auto" and self.nanosecond):
if self.microsecond:
base1 += f"{self.nanosecond:03d}"
else:
base1 += f".{self.nanosecond:09d}"

return base1 + base2

Expand Down
3 changes: 2 additions & 1 deletion pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
assert_extension_array_equal,
assert_frame_equal,
assert_index_equal,
assert_indexing_slices_equivalent,
assert_interval_array_equal,
assert_is_sorted,
assert_is_valid_plot_return_object,
Expand Down Expand Up @@ -259,7 +260,7 @@ def box_expected(expected, box_cls, transpose=True):
expected = DatetimeArray(expected)
elif box_cls is TimedeltaArray:
expected = TimedeltaArray(expected)
elif box_cls is np.ndarray:
elif box_cls is np.ndarray or box_cls is np.array:
expected = np.array(expected)
elif box_cls is to_array:
expected = to_array(expected)
Expand Down
Loading