Theano/PyMC3 Dot Product Error (Potential DGEMM failure) - theano

I am attempting to use theano with pymc3 to make a model as shown
from scipy import stats
N = 100
height = stats.norm.rvs(size=N, loc=10, scale=2)
leg_prop = stats.uniform.rvs(size=N, loc=0.4, scale=0.5)
leg_left = leg_prop * height + stats.norm.rvs(size=N, loc=0, scale=0.02)
leg_right = leg_prop * height + stats.norm.rvs(size=N, loc=0, scale=0.02)
import matplotlib.pyplot as plt
import pymc3 as pm
import numpy as np
%matplotlib inline
leg_length = np.array([leg_left, leg_right])
leg_mean = leg_length.mean()
print leg_length.mean()
with pm.Model() as model_mvlr:
alpha_centered = pm.Normal('alpha_centered', mu=0, sd=10)
beta = pm.Normal('beta', mu=0, sd=1, shape=2)
epsilon = pm.HalfCauchy('epsilon', 5)
mu = alpha_centered+pm.math.dot(beta, leg_length)
alpha = pm.Deterministic('alpha', alpha_centered-pm.math.dot(beta, leg_mean))
height_pred = pm.Normal('height_pred', mu=mu, sd=epsilon, observed=height)
trace_height = pm.sample(size=5000, njobs=1)
upon which I get the error below which seems to have a problem with the dgemm implementation from what I can gather, making me think that the pm.dot call is the culprit. I need to use this call however and so any advice on how to remedy this would be much appreciated.
Here is the (rather long) error:
You can find the C code in this temporary file: c:\users\notle_~1\appdata\local\temp\theano_compilation_error_i_ayvf
Exception Traceback (most recent call last)
in ()
17 height_pred = pm.Normal('height_pred', mu=mu, sd=epsilon, observed=height)
18
---> 19 trace_height = pm.sample(size=5000, njobs=1)
C:\Users\notle_000\Anaconda2\lib\site-packages\pymc3\sampling.pyc in sample(draws, step, init, n_init, start, trace, chain_idx, chains, njobs, tune, nuts_kwargs, step_kwargs, progressbar, model, random_seed, live_plot, discard_tuned_samples, live_plot_kwargs, compute_convergence_checks, **kwargs)
371 start_, step = init_nuts(init=init, chains=chains, n_init=n_init,
372 model=model, random_seed=random_seed,
--> 373 progressbar=progressbar, **args)
374 if start is None:
375 start = start_
C:\Users\notle_000\Anaconda2\lib\site-packages\pymc3\sampling.pyc in init_nuts(init, chains, n_init, model, random_seed, progressbar, **kwargs)
1352 'Unknown initializer: {}.'.format(init))
1353
-> 1354 step = pm.NUTS(potential=potential, model=model, **kwargs)
1355
1356 return start, step
C:\Users\notle_000\Anaconda2\lib\site-packages\pymc3\step_methods\hmc\nuts.pyc in init(self, vars, max_treedepth, early_max_treedepth, **kwargs)
150 pm.sample to the desired number of tuning steps.
151 """
--> 152 super(NUTS, self).init(vars, **kwargs)
153
154 self.max_treedepth = max_treedepth
C:\Users\notle_000\Anaconda2\lib\site-packages\pymc3\step_methods\hmc\base_hmc.pyc in init(self, vars, scaling, step_scale, is_cov, model, blocked, potential, integrator, dtype, Emax, target_accept, gamma, k, t0, adapt_step_size, step_rand, **theano_kwargs)
61
62 super(BaseHMC, self).init(vars, blocked=blocked, model=model,
---> 63 dtype=dtype, **theano_kwargs)
64
65 self.adapt_step_size = adapt_step_size
C:\Users\notle_000\Anaconda2\lib\site-packages\pymc3\step_methods\arraystep.pyc in init(self, vars, model, blocked, dtype, **theano_kwargs)
213
214 self._logp_dlogp_func = model.logp_dlogp_function(
--> 215 vars, dtype=dtype, **theano_kwargs)
216
217 def step(self, point):
C:\Users\notle_000\Anaconda2\lib\site-packages\pymc3\model.pyc in logp_dlogp_function(self, grad_vars, **kwargs)
656 varnames = [var.name for var in grad_vars]
657 extra_vars = [var for var in self.free_RVs if var.name not in varnames]
--> 658 return ValueGradFunction(self.logpt, grad_vars, extra_vars, **kwargs)
659
660 #property
C:\Users\notle_000\Anaconda2\lib\site-packages\pymc3\model.pyc in init(self, cost, grad_vars, extra_vars, dtype, casting, **kwargs)
403
404 self._theano_function = theano.function(
--> 405 inputs, [self._cost_joined, grad], givens=givens, **kwargs)
406
407 def set_extra_values(self, extra_vars):
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\compile\function.pyc in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
315 on_unused_input=on_unused_input,
316 profile=profile,
--> 317 output_keys=output_keys)
318 return fn
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\compile\pfunc.pyc in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
484 accept_inplace=accept_inplace, name=name,
485 profile=profile, on_unused_input=on_unused_input,
--> 486 output_keys=output_keys)
487
488
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\compile\function_module.pyc in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
1839 name=name)
1840 with theano.change_flags(compute_test_value="off"):
-> 1841 fn = m.create(defaults)
1842 finally:
1843 t2 = time.time()
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\compile\function_module.pyc in create(self, input_storage, trustme, storage_map)
1713 theano.config.traceback.limit = theano.config.traceback.compile_limit
1714 _fn, _i, _o = self.linker.make_thunk(
-> 1715 input_storage=input_storage_lists, storage_map=storage_map)
1716 finally:
1717 theano.config.traceback.limit = limit_orig
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\link.pyc in make_thunk(self, input_storage, output_storage, storage_map)
697 return self.make_all(input_storage=input_storage,
698 output_storage=output_storage,
--> 699 storage_map=storage_map)[:3]
700
701 def make_all(self, input_storage, output_storage):
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\vm.pyc in make_all(self, profiler, input_storage, output_storage, storage_map)
1082 compute_map,
1083 [],
-> 1084 impl=impl))
1085 linker_make_thunk_time[node] = time.time() - thunk_start
1086 if not hasattr(thunks[-1], 'lazy'):
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\op.pyc in make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
953 try:
954 return self.make_c_thunk(node, storage_map, compute_map,
--> 955 no_recycling)
956 except (NotImplementedError, utils.MethodNotDefined):
957 # We requested the c code, so don't catch the error.
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\op.pyc in make_c_thunk(self, node, storage_map, compute_map, no_recycling)
856 _logger.debug('Trying CLinker.make_thunk')
857 outputs = cl.make_thunk(input_storage=node_input_storage,
--> 858 output_storage=node_output_storage)
859 thunk, node_input_filters, node_output_filters = outputs
860
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\cc.pyc in make_thunk(self, input_storage, output_storage, storage_map, keep_lock)
1215 cthunk, module, in_storage, out_storage, error_storage = self.compile(
1216 input_storage, output_storage, storage_map,
-> 1217 keep_lock=keep_lock)
1218
1219 res = _CThunk(cthunk, init_tasks, tasks, error_storage, module)
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\cc.pyc in compile(self, input_storage, output_storage, storage_map, keep_lock)
1155 output_storage,
1156 storage_map,
-> 1157 keep_lock=keep_lock)
1158 return (thunk,
1159 module,
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\cc.pyc in cthunk_factory(self, error_storage, in_storage, out_storage, storage_map, keep_lock)
1618 node.op.prepare_node(node, storage_map, None, 'c')
1619 module = get_module_cache().module_from_key(
-> 1620 key=key, lnk=self, keep_lock=keep_lock)
1621
1622 vars = self.inputs + self.outputs + self.orphans
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\cmodule.pyc in module_from_key(self, key, lnk, keep_lock)
1172 try:
1173 location = dlimport_workdir(self.dirname)
-> 1174 module = lnk.compile_cmodule(location)
1175 name = module.file
1176 assert name.startswith(location)
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\cc.pyc in compile_cmodule(self, location)
1521 lib_dirs=self.lib_dirs(),
1522 libs=libs,
-> 1523 preargs=preargs)
1524 except Exception as e:
1525 e.args += (str(self.fgraph),)
C:\Users\notle_000\Anaconda2\lib\site-packages\theano\gof\cmodule.pyc in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
2357 # difficult to read.
2358 raise Exception('Compilation failed (return status=%s): %s' %
-> 2359 (status, compile_stderr.replace('\n', '. ')))
2360 elif config.cmodule.compilation_warning and compile_stderr:
2361 # Print errors just below the command line.
Exception: ('The following error happened while compiling the node', CGemv{inplace}(AllocEmpty{dtype='float64'}.0, TensorConstant{1.0}, TensorConstant{[[ 8.40619..90000243]]}, beta, TensorConstant{0.0}), '\n', "Compilation failed (return status=1): C:\Users\NOTLE_~1\AppData\Local\Temp\cc6eSkXb.o: In function run':\r. C:/Users/notle_000/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.12-64/tmppb73ml/mod.cpp:1261: undefined reference todgemv_'\r. C:/Users/notle_000/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.12-64/tmppb73ml/mod.cpp:1233: undefined reference to sgemv_'\r. C:/Users/notle_000/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.12-64/tmppb73ml/mod.cpp:1224: undefined reference tosdot_'\r. C:/Users/notle_000/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.12-64/tmppb73ml/mod.cpp:1190: undefined reference to dgemv_'\r. C:/Users/notle_000/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.12-64/tmppb73ml/mod.cpp:1252: undefined reference toddot_'\r. C:/Users/notle_000/AppData/Local/Theano/compiledir_Windows-10-10.0.16299-Intel64_Family_6_Model_58_Stepping_9_GenuineIntel-2.7.12-64/tmppb73ml/mod.cpp:1180: undefined reference to `sgemv_'\r. collect2.exe: error: ld returned 1 exit status\r. ", '[CGemv{inplace}(, TensorConstant{1.0}, TensorConstant{[[ 8.40619..90000243]]}, beta, TensorConstant{0.0})]')

Related

Colab IndexError: Target 255 is out of bounds

I'm trying to perform an image semantic segmentation (segment mining fields) using lightning-flash. My images are all RGB/uint8/512x512 and the masks are L/uint8/512x512.
When I run the code, I get an error when fitting.
My code is this one:
import torch
import flash
from flash.image import SemanticSegmentation, SemanticSegmentationData
import os
from google.colab import drive
import ssl
drive.mount("/content/drive")
DATA_DIR = '/content/drive/MyDrive/data/'
x_train_dir = os.path.join(DATA_DIR, 'train_images')
y_train_dir = os.path.join(DATA_DIR, 'train_masks')
x_valid_dir = os.path.join(DATA_DIR, 'val_images')
y_valid_dir = os.path.join(DATA_DIR, 'val_masks')
x_test_dir = os.path.join(DATA_DIR, 'test_images')
y_test_dir = os.path.join(DATA_DIR, 'test_masks')
datamodule = SemanticSegmentationData.from_folders(
train_folder=x_train_dir,
train_target_folder=y_train_dir,
val_folder=x_valid_dir,
val_target_folder=y_valid_dir,
test_folder=x_test_dir,
test_target_folder=y_test_dir,
transform_kwargs=dict(image_size=(256, 256)),
num_classes=1,
batch_size=16,
)
#avoid ssl error
ssl._create_default_https_context = ssl._create_unverified_context
model = SemanticSegmentation(
head="unetplusplus",
backbone="densenet169",
pretrained="imagenet",
num_classes=datamodule.num_classes
)
GPUS = torch.cuda.device_count()
if GPUS > 0:
trainer = flash.Trainer(max_epochs=2, gpus=torch.cuda.device_count())
else:
trainer = flash.Trainer(max_epochs=2)
trainer.finetune(model, datamodule=datamodule, strategy="freeze")
trainer.save_checkpoint("semantic_segmentation_model.pt")
When I run the code, I get this error:
IndexError Traceback (most recent call last)
<ipython-input-7-11e2ce087ca0> in <module>
6
7 #trainer.fit(model, datamodule=datamodule)
----> 8 trainer.finetune(model, datamodule=datamodule, strategy="freeze")
9 trainer.save_checkpoint("semantic_segmentation_model.pt")
19 frames
/usr/local/lib/python3.7/dist-packages/flash/core/trainer.py in finetune(self, model, train_dataloader, val_dataloaders, datamodule, strategy, train_bn)
162 """
163 self._resolve_callbacks(model, strategy, train_bn=train_bn)
--> 164 return super().fit(model, train_dataloader, val_dataloaders, datamodule)
165
166 def predict(
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in fit(self, model, train_dataloaders, val_dataloaders, datamodule, ckpt_path)
695 self.strategy.model = model
696 self._call_and_handle_interrupt(
--> 697 self._fit_impl, model, train_dataloaders, val_dataloaders, datamodule, ckpt_path
698 )
699
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in _call_and_handle_interrupt(self, trainer_fn, *args, **kwargs)
648 return self.strategy.launcher.launch(trainer_fn, *args, trainer=self, **kwargs)
649 else:
--> 650 return trainer_fn(*args, **kwargs)
651 # TODO(awaelchli): Unify both exceptions below, where `KeyboardError` doesn't re-raise
652 except KeyboardInterrupt as exception:
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in _fit_impl(self, model, train_dataloaders, val_dataloaders, datamodule, ckpt_path)
735 ckpt_path, model_provided=True, model_connected=self.lightning_module is not None
736 )
--> 737 results = self._run(model, ckpt_path=self.ckpt_path)
738
739 assert self.state.stopped
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in _run(self, model, ckpt_path)
1166 self._checkpoint_connector.resume_end()
1167
-> 1168 results = self._run_stage()
1169
1170 log.detail(f"{self.__class__.__name__}: trainer tearing down")
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in _run_stage(self)
1252 if self.predicting:
1253 return self._run_predict()
-> 1254 return self._run_train()
1255
1256 def _pre_training_routine(self):
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in _run_train(self)
1274
1275 with isolate_rng():
-> 1276 self._run_sanity_check()
1277
1278 # enable train mode
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in _run_sanity_check(self)
1343 # run eval step
1344 with torch.no_grad():
-> 1345 val_loop.run()
1346
1347 self._call_callback_hooks("on_sanity_check_end")
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/loops/loop.py in run(self, *args, **kwargs)
198 try:
199 self.on_advance_start(*args, **kwargs)
--> 200 self.advance(*args, **kwargs)
201 self.on_advance_end()
202 self._restarting = False
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/loops/dataloader/evaluation_loop.py in advance(self, *args, **kwargs)
153 if self.num_dataloaders > 1:
154 kwargs["dataloader_idx"] = dataloader_idx
--> 155 dl_outputs = self.epoch_loop.run(self._data_fetcher, dl_max_batches, kwargs)
156
157 # store batch level output per dataloader
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/loops/loop.py in run(self, *args, **kwargs)
198 try:
199 self.on_advance_start(*args, **kwargs)
--> 200 self.advance(*args, **kwargs)
201 self.on_advance_end()
202 self._restarting = False
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/loops/epoch/evaluation_epoch_loop.py in advance(self, data_fetcher, dl_max_batches, kwargs)
141
142 # lightning module methods
--> 143 output = self._evaluation_step(**kwargs)
144 output = self._evaluation_step_end(output)
145
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/loops/epoch/evaluation_epoch_loop.py in _evaluation_step(self, **kwargs)
238 """
239 hook_name = "test_step" if self.trainer.testing else "validation_step"
--> 240 output = self.trainer._call_strategy_hook(hook_name, *kwargs.values())
241
242 return output
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/trainer/trainer.py in _call_strategy_hook(self, hook_name, *args, **kwargs)
1704
1705 with self.profiler.profile(f"[Strategy]{self.strategy.__class__.__name__}.{hook_name}"):
-> 1706 output = fn(*args, **kwargs)
1707
1708 # restore current_fx when nested context
/usr/local/lib/python3.7/dist-packages/pytorch_lightning/strategies/strategy.py in validation_step(self, *args, **kwargs)
368 with self.precision_plugin.val_step_context():
369 assert isinstance(self.model, ValidationStep)
--> 370 return self.model.validation_step(*args, **kwargs)
371
372 def test_step(self, *args: Any, **kwargs: Any) -> Optional[STEP_OUTPUT]:
/usr/local/lib/python3.7/dist-packages/flash/image/segmentation/model.py in validation_step(self, batch, batch_idx)
151 def validation_step(self, batch: Any, batch_idx: int) -> Any:
152 batch = (batch[DataKeys.INPUT], batch[DataKeys.TARGET])
--> 153 return super().validation_step(batch, batch_idx)
154
155 def test_step(self, batch: Any, batch_idx: int) -> Any:
/usr/local/lib/python3.7/dist-packages/flash/core/model.py in validation_step(self, batch, batch_idx)
423
424 def validation_step(self, batch: Any, batch_idx: int) -> None:
--> 425 output = self.step(batch, batch_idx, self.val_metrics)
426 log_kwargs = {"batch_size": output.get(OutputKeys.BATCH_SIZE, None)} if _PL_GREATER_EQUAL_1_5_0 else {}
427 self.log_dict(
/usr/local/lib/python3.7/dist-packages/flash/core/model.py in step(self, batch, batch_idx, metrics)
360 output = {OutputKeys.OUTPUT: y_hat}
361 y_hat = self.to_loss_format(output[OutputKeys.OUTPUT])
--> 362 losses = {name: l_fn(y_hat, y) for name, l_fn in self.loss_fn.items()}
363
364 y_hat = self.to_metrics_format(output[OutputKeys.OUTPUT])
/usr/local/lib/python3.7/dist-packages/flash/core/model.py in <dictcomp>(.0)
360 output = {OutputKeys.OUTPUT: y_hat}
361 y_hat = self.to_loss_format(output[OutputKeys.OUTPUT])
--> 362 losses = {name: l_fn(y_hat, y) for name, l_fn in self.loss_fn.items()}
363
364 y_hat = self.to_metrics_format(output[OutputKeys.OUTPUT])
/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing)
3012 if size_average is not None or reduce is not None:
3013 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 3014 return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
3015
3016
IndexError: Target 255 is out of bounds.
How can I solve this problem? I researched others issues on stackoverflow and they were all related to the number of classes. But in my case, I only want to segment mining fields.

M1 MacBook Apple ML compute Tensorflow2.4 compatibility issue with Numpy

I am running the new apple native tensorflow package 2.4, and ran into a problem I did not have before. This jupyter notebook code works in old intel based environment where an older tensorflow version was used. But with M1 apple MLcomputer TensorFlow2.4 it is not compatible
with Numpy 1.20 or 1.18(I downgraded numpy to try). The error log:
NotImplementedError: Cannot convert a symbolic Tensor (lstm_1/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
<ipython-input-20-73358e637fe3> in <module>
4 model = Sequential()
5 model.add(Embedding(vocab_size+1, W2V_SIZE, weights=[embedding_matrix], input_length=MAX_SEQUENCE_LENGTH, trainable=False))
----> 6 model.add(LSTM(500, dropout=0.2, recurrent_dropout=0.2))
7 model.add(Dense(units = 10000, kernel_initializer = 'glorot_uniform', activation = 'relu'))
8 model.add(Dropout(0.35))
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
515 self._self_setattr_tracking = False # pylint: disable=protected-access
516 try:
--> 517 result = method(self, *args, **kwargs)
518 finally:
519 self._self_setattr_tracking = previous_value # pylint: disable=protected-access
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/engine/sequential.py in add(self, layer)
221 # If the model is being built continuously on top of an input layer:
222 # refresh its output.
--> 223 output_tensor = layer(self.outputs[0])
224 if len(nest.flatten(output_tensor)) != 1:
225 raise ValueError(SINGLE_LAYER_OUTPUT_ERROR_MSG)
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in __call__(self, inputs, initial_state, constants, **kwargs)
658
659 if initial_state is None and constants is None:
--> 660 return super(RNN, self).__call__(inputs, **kwargs)
661
662 # If any of `initial_state` or `constants` are specified and are Keras
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in __call__(self, *args, **kwargs)
944 # >> model = tf.keras.Model(inputs, outputs)
945 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
--> 946 return self._functional_construction_call(inputs, args, kwargs,
947 input_list)
948
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1083 layer=self, inputs=inputs, build_graph=True, training=training_value):
1084 # Check input assumptions set after layer building, e.g. input shape.
-> 1085 outputs = self._keras_tensor_symbolic_call(
1086 inputs, input_masks, args, kwargs)
1087
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in _keras_tensor_symbolic_call(self, inputs, input_masks, args, kwargs)
815 return nest.map_structure(keras_tensor.KerasTensor, output_signature)
816 else:
--> 817 return self._infer_output_signature(inputs, args, kwargs, input_masks)
818
819 def _infer_output_signature(self, inputs, args, kwargs, input_masks):
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/engine/base_layer.py in _infer_output_signature(self, inputs, args, kwargs, input_masks)
856 # TODO(kaftan): do we maybe_build here, or have we already done it?
857 self._maybe_build(inputs)
--> 858 outputs = call_fn(inputs, *args, **kwargs)
859
860 self._handle_activity_regularization(inputs, outputs)
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent_v2.py in call(self, inputs, mask, training, initial_state)
1161 # LSTM does not support constants. Ignore it during process.
1162 orig_initial_state = initial_state
-> 1163 inputs, initial_state, _ = self._process_inputs(inputs, initial_state, None)
1164
1165 if isinstance(mask, list):
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in _process_inputs(self, inputs, initial_state, constants)
857 initial_state = self.states
858 elif initial_state is None:
--> 859 initial_state = self.get_initial_state(inputs)
860
861 if len(initial_state) != len(self.states):
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in get_initial_state(self, inputs)
640 dtype = inputs.dtype
641 if get_initial_state_fn:
--> 642 init_state = get_initial_state_fn(
643 inputs=None, batch_size=batch_size, dtype=dtype)
644 else:
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in get_initial_state(self, inputs, batch_size, dtype)
2504
2505 def get_initial_state(self, inputs=None, batch_size=None, dtype=None):
-> 2506 return list(_generate_zero_filled_state_for_cell(
2507 self, inputs, batch_size, dtype))
2508
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in _generate_zero_filled_state_for_cell(cell, inputs, batch_size, dtype)
2985 batch_size = array_ops.shape(inputs)[0]
2986 dtype = inputs.dtype
-> 2987 return _generate_zero_filled_state(batch_size, cell.state_size, dtype)
2988
2989
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in _generate_zero_filled_state(batch_size_tensor, state_size, dtype)
3001
3002 if nest.is_nested(state_size):
-> 3003 return nest.map_structure(create_zeros, state_size)
3004 else:
3005 return create_zeros(state_size)
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/util/nest.py in map_structure(func, *structure, **kwargs)
657
658 return pack_sequence_as(
--> 659 structure[0], [func(*x) for x in entries],
660 expand_composites=expand_composites)
661
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/util/nest.py in <listcomp>(.0)
657
658 return pack_sequence_as(
--> 659 structure[0], [func(*x) for x in entries],
660 expand_composites=expand_composites)
661
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/keras/layers/recurrent.py in create_zeros(unnested_state_size)
2998 flat_dims = tensor_shape.TensorShape(unnested_state_size).as_list()
2999 init_state_size = [batch_size_tensor] + flat_dims
-> 3000 return array_ops.zeros(init_state_size, dtype=dtype)
3001
3002 if nest.is_nested(state_size):
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs)
199 """Call target, and fall back on dispatchers if there is a TypeError."""
200 try:
--> 201 return target(*args, **kwargs)
202 except (TypeError, ValueError):
203 # Note: convert_to_eager_tensor currently raises a ValueError, not a
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py in wrapped(*args, **kwargs)
2817
2818 def wrapped(*args, **kwargs):
-> 2819 tensor = fun(*args, **kwargs)
2820 tensor._is_zeros_tensor = True
2821 return tensor
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py in zeros(shape, dtype, name)
2866 # Create a constant if it won't be very big. Otherwise create a fill
2867 # op to prevent serialized GraphDefs from becoming too large.
-> 2868 output = _constant_if_small(zero, shape, dtype, name)
2869 if output is not None:
2870 return output
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py in _constant_if_small(value, shape, dtype, name)
2802 def _constant_if_small(value, shape, dtype, name):
2803 try:
-> 2804 if np.prod(shape) < 1000:
2805 return constant(value, shape=shape, dtype=dtype, name=name)
2806 except TypeError:
<__array_function__ internals> in prod(*args, **kwargs)
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/numpy/core/fromnumeric.py in prod(a, axis, dtype, out, keepdims, initial, where)
3028 10
3029 """
-> 3030 return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
3031 keepdims=keepdims, initial=initial, where=where)
3032
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/numpy/core/fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
85 return reduction(axis=axis, out=out, **passkwargs)
86
---> 87 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
88
89
~/miniforge3/envs/tf2.4/lib/python3.8/site-packages/tensorflow/python/framework/ops.py in __array__(self)
850
851 def __array__(self):
--> 852 raise NotImplementedError(
853 "Cannot convert a symbolic Tensor ({}) to a numpy array."
854 " This error may indicate that you're trying to pass a Tensor to"
NotImplementedError: Cannot convert a symbolic Tensor (lstm_1/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

AttributeError: /home/hp/anaconda3/lib/libxgboost.so: undefined symbol: XGDMatrixSetDenseInfo

I have installed XGBoost with pip3.
While trying to run this line:
clf = GridSearchCV(estimator=xgb.XGBClassifier(use_label_encoder =False), param_grid=params, scoring = 'accuracy', cv=20).fit(data_train, label_train)
I get this error :
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-90-718a4a11a2ba> in <module>
4 startTime = time.time()
5
----> 6 clf = GridSearchCV(estimator=xgb.XGBClassifier(use_label_encoder =False), param_grid=params, scoring = 'accuracy', cv=20).fit(data_train, label_train)
7 print(clf.best_estimator_)
8 print('--------------------------------------------------')
~/anaconda3/lib/python3.8/site-packages/sklearn/utils/validation.py in inner_f(*args, **kwargs)
61 extra_args = len(args) - len(all_args)
62 if extra_args <= 0:
---> 63 return f(*args, **kwargs)
64
65 # extra_args > 0
~/anaconda3/lib/python3.8/site-packages/sklearn/model_selection/_search.py in fit(self, X, y, groups, **fit_params)
878 refit_start_time = time.time()
879 if y is not None:
--> 880 self.best_estimator_.fit(X, y, **fit_params)
881 else:
882 self.best_estimator_.fit(X, **fit_params)
~/anaconda3/lib/python3.8/site-packages/xgboost/core.py in inner_f(*args, **kwargs)
420 for k, arg in zip(sig.parameters, args):
421 kwargs[k] = arg
--> 422 return f(**kwargs)
423
424 return inner_f
~/anaconda3/lib/python3.8/site-packages/xgboost/sklearn.py in fit(self, X, y, sample_weight, base_margin, eval_set, eval_metric, early_stopping_rounds, verbose, xgb_model, sample_weight_eval_set, feature_weights, callbacks)
901 self.n_features_in_ = self._features_count
902
--> 903 train_dmatrix, evals = self._wrap_evaluation_matrices(
904 X, y, group=None, sample_weight=sample_weight, base_margin=base_margin,
905 feature_weights=feature_weights,
~/anaconda3/lib/python3.8/site-packages/xgboost/sklearn.py in _wrap_evaluation_matrices(self, X, y, group, sample_weight, base_margin, feature_weights, eval_set, sample_weight_eval_set, eval_group, label_transform)
263
264 y = label_transform(y)
--> 265 train_dmatrix = DMatrix(data=X, label=y, weight=sample_weight,
266 base_margin=base_margin,
267 missing=self.missing, nthread=self.n_jobs)
~/anaconda3/lib/python3.8/site-packages/xgboost/core.py in __init__(self, data, label, weight, base_margin, missing, silent, feature_names, feature_types, nthread, enable_categorical)
507 self.handle = handle
508
--> 509 self.set_info(label=label, weight=weight, base_margin=base_margin)
510
511 self.feature_names = feature_names
~/anaconda3/lib/python3.8/site-packages/xgboost/core.py in inner_f(*args, **kwargs)
420 for k, arg in zip(sig.parameters, args):
421 kwargs[k] = arg
--> 422 return f(**kwargs)
423
424 return inner_f
~/anaconda3/lib/python3.8/site-packages/xgboost/core.py in set_info(self, label, weight, base_margin, group, label_lower_bound, label_upper_bound, feature_names, feature_types, feature_weights)
528 '''Set meta info for DMatrix.'''
529 if label is not None:
--> 530 self.set_label(label)
531 if weight is not None:
532 self.set_weight(weight)
~/anaconda3/lib/python3.8/site-packages/xgboost/core.py in set_label(self, label)
657 """
658 from .data import dispatch_meta_backend
--> 659 dispatch_meta_backend(self, label, 'label', 'float')
660
661 def set_weight(self, weight):
~/anaconda3/lib/python3.8/site-packages/xgboost/data.py in dispatch_meta_backend(matrix, data, name, dtype)
674 data = data.values.astype('float')
675 assert len(data.shape) == 1 or data.shape[1] == 0 or data.shape[1] == 1
--> 676 _meta_from_numpy(data, name, dtype, handle)
677 return
678 if _is_dlpack(data):
~/anaconda3/lib/python3.8/site-packages/xgboost/data.py in _meta_from_numpy(data, field, dtype, handle)
598 ptr = interface['data'][0]
599 ptr = ctypes.c_void_p(ptr)
--> 600 _check_call(_LIB.XGDMatrixSetDenseInfo(
601 handle,
602 c_str(field),
~/anaconda3/lib/python3.8/ctypes/__init__.py in __getattr__(self, name)
392 if name.startswith('__') and name.endswith('__'):
393 raise AttributeError(name)
--> 394 func = self.__getitem__(name)
395 setattr(self, name, func)
396 return func
~/anaconda3/lib/python3.8/ctypes/__init__.py in __getitem__(self, name_or_ordinal)
397
398 def __getitem__(self, name_or_ordinal):
--> 399 func = self._FuncPtr((name_or_ordinal, self))
400 if not isinstance(name_or_ordinal, int):
401 func.__name__ = name_or_ordinal
AttributeError: /home/hp/anaconda3/lib/libxgboost.so: undefined symbol: XGDMatrixSetDenseInfo

Pandas cannot plot timeseries imported from Excel

This is my DataFrame obtained importing from an Excel .xls
0 1
664 2017-12-07 19:08:54 1.1377
665 2017-12-07 19:10:31 1.1374
666 2017-12-07 19:12:17 1.1377
667 2017-12-07 19:13:28 1.1377
668 2017-12-07 19:15:25 1.1379
I think is correclty typed
0 datetime64[ns]
1 float64
dtype: object
However it does not plot with ax = _df.plot() because of some error. Any idea why?
This is my first hour in Pandas, sorry if it's classic question, but I saw only not relevant answers on this ValueError: ordinal must be >= 1
Thanks for your inputs
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-24-ca306a836171> in <module>()
----> 1 ax = _df.plot()
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2671 fontsize=fontsize, colormap=colormap, table=table,
2672 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 2673 sort_columns=sort_columns, **kwds)
2674 __call__.__doc__ = plot_frame.__doc__
2675
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
1898 yerr=yerr, xerr=xerr,
1899 secondary_y=secondary_y, sort_columns=sort_columns,
-> 1900 **kwds)
1901
1902
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
1725 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
1726
-> 1727 plot_obj.generate()
1728 plot_obj.draw()
1729 return plot_obj.result
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in generate(self)
258
259 for ax in self.axes:
--> 260 self._post_plot_logic_common(ax, self.data)
261 self._post_plot_logic(ax, self.data)
262
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in _post_plot_logic_common(self, ax, data)
393 self._apply_axis_properties(ax.xaxis, rot=self.rot,
394 fontsize=self.fontsize)
--> 395 self._apply_axis_properties(ax.yaxis, fontsize=self.fontsize)
396
397 if hasattr(ax, 'right_ax'):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pandas/plotting/_core.py in _apply_axis_properties(self, axis, rot, fontsize)
466
467 def _apply_axis_properties(self, axis, rot=None, fontsize=None):
--> 468 labels = axis.get_majorticklabels() + axis.get_minorticklabels()
469 for label in labels:
470 if rot is not None:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in get_majorticklabels(self)
1189 def get_majorticklabels(self):
1190 'Return a list of Text instances for the major ticklabels'
-> 1191 ticks = self.get_major_ticks()
1192 labels1 = [tick.label1 for tick in ticks if tick.label1On]
1193 labels2 = [tick.label2 for tick in ticks if tick.label2On]
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in get_major_ticks(self, numticks)
1318 'get the tick instances; grow as necessary'
1319 if numticks is None:
-> 1320 numticks = len(self.get_major_locator()())
1321 if len(self.majorTicks) < numticks:
1322 # update the new tick label properties from the old
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in __call__(self)
984 def __call__(self):
985 'Return the locations of the ticks'
--> 986 self.refresh()
987 return self._locator()
988
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in refresh(self)
1004 def refresh(self):
1005 'Refresh internal information based on current limits.'
-> 1006 dmin, dmax = self.viewlim_to_dt()
1007 self._locator = self.get_locator(dmin, dmax)
1008
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in viewlim_to_dt(self)
761 vmin, vmax = vmax, vmin
762
--> 763 return num2date(vmin, self.tz), num2date(vmax, self.tz)
764
765 def _get_unit(self):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in num2date(x, tz)
399 tz = _get_rc_timezone()
400 if not cbook.iterable(x):
--> 401 return _from_ordinalf(x, tz)
402 else:
403 x = np.asarray(x)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
252
253 ix = int(x)
--> 254 dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
255
256 remainder = float(x) - ix
ValueError: ordinal must be >= 1
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
330 pass
331 else:
--> 332 return printer(obj)
333 # Finally look for special method names
334 method = get_real_method(obj, self.print_method)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/pylabtools.py in <lambda>(fig)
235
236 if 'png' in formats:
--> 237 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
238 if 'retina' in formats or 'png2x' in formats:
239 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
119
120 bytes_io = BytesIO()
--> 121 fig.canvas.print_figure(bytes_io, **kw)
122 data = bytes_io.getvalue()
123 if fmt == 'svg':
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
2198 orientation=orientation,
2199 dryrun=True,
-> 2200 **kwargs)
2201 renderer = self.figure._cachedRenderer
2202 bbox_inches = self.figure.get_tightbbox(renderer)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
543
544 def print_png(self, filename_or_obj, *args, **kwargs):
--> 545 FigureCanvasAgg.draw(self)
546 renderer = self.get_renderer()
547 original_dpi = renderer.dpi
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/backend_agg.py in draw(self)
462
463 try:
--> 464 self.figure.draw(self.renderer)
465 finally:
466 RendererAgg.lock.release()
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/figure.py in draw(self, renderer)
1142
1143 mimage._draw_list_compositing_images(
-> 1144 renderer, self, dsu, self.suppressComposite)
1145
1146 renderer.close_group('figure')
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)
2424 renderer.stop_rasterizing()
2425
-> 2426 mimage._draw_list_compositing_images(renderer, self, dsu)
2427
2428 renderer.close_group('axes')
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, dsu, suppress_composite)
137 if not_composite or not has_images:
138 for zorder, a in dsu:
--> 139 a.draw(renderer)
140 else:
141 # Composite any adjacent images together
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
61 def draw_wrapper(artist, renderer, *args, **kwargs):
62 before(artist, renderer)
---> 63 draw(artist, renderer, *args, **kwargs)
64 after(artist, renderer)
65
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in draw(self, renderer, *args, **kwargs)
1134 renderer.open_group(__name__)
1135
-> 1136 ticks_to_draw = self._update_ticks(renderer)
1137 ticklabelBoxes, ticklabelBoxes2 = self._get_tick_bboxes(ticks_to_draw,
1138 renderer)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in _update_ticks(self, renderer)
967
968 interval = self.get_view_interval()
--> 969 tick_tups = [t for t in self.iter_ticks()]
970 if self._smart_bounds:
971 # handle inverted limits
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in <listcomp>(.0)
967
968 interval = self.get_view_interval()
--> 969 tick_tups = [t for t in self.iter_ticks()]
970 if self._smart_bounds:
971 # handle inverted limits
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/axis.py in iter_ticks(self)
910 Iterate through all of the major and minor ticks.
911 """
--> 912 majorLocs = self.major.locator()
913 majorTicks = self.get_major_ticks(len(majorLocs))
914 self.major.formatter.set_locs(majorLocs)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in __call__(self)
984 def __call__(self):
985 'Return the locations of the ticks'
--> 986 self.refresh()
987 return self._locator()
988
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in refresh(self)
1004 def refresh(self):
1005 'Refresh internal information based on current limits.'
-> 1006 dmin, dmax = self.viewlim_to_dt()
1007 self._locator = self.get_locator(dmin, dmax)
1008
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in viewlim_to_dt(self)
761 vmin, vmax = vmax, vmin
762
--> 763 return num2date(vmin, self.tz), num2date(vmax, self.tz)
764
765 def _get_unit(self):
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in num2date(x, tz)
399 tz = _get_rc_timezone()
400 if not cbook.iterable(x):
--> 401 return _from_ordinalf(x, tz)
402 else:
403 x = np.asarray(x)
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/dates.py in _from_ordinalf(x, tz)
252
253 ix = int(x)
--> 254 dt = datetime.datetime.fromordinal(ix).replace(tzinfo=UTC)
255
256 remainder = float(x) - ix
ValueError: ordinal must be >= 1
<matplotlib.figure.Figure at 0x118f1e978>
You probably want to plot column 1 agains column 0, i.e. the numbers against the dates? This would be done via
df.plot(x=0,y=1)
Your columns are unnamed. So you may also name them and reset the index to something useful (or as below, not so useful ;-))
df.columns = ["0", "1"]
df = df.set_index("0")
df.plot()
Both should give you a plot like the following:

matplotlib plot_date AttributeError: 'numpy.datetime64' object has no attribute 'toordinal' [duplicate]

This question already has answers here:
pandas 0.21.0 Timestamp compatibility issue with matplotlib
(3 answers)
Closed 5 years ago.
I'm getting the following error with plot_date in matplotlib - example in jupyter notebook below.
python version 3.6.3
pandas version 0.21.0
matplotlib 2.1.0
import pandas as pd
%pylab inline
datelist = pd.date_range(pd.datetime.today(), periods=100).tolist()
vals = np.random.rand(100,1)
No error - list of pandas._libs.tslib.Timestamp and array of values:
plt.plot_date(datelist, vals, xdate=True);
AttributeError - pandas DataFrame with DataTimeIndex:
Note: there is no error when I use python 3.4.5, matplotlib 1.5.1, pandas 0.19.2
Edit start
Insert below lines for workaround as per Pandas v0.21.0 What's New and duplicate answer.
from pandas.tseries import converter
converter.register()
Edit end
df = pd.DataFrame(data=vals, index=datelist)
plt.plot_date(df.index, df[0], xdate=True);
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-22-c438634aa06b> in <module>()
----> 1 plt.plot_date(df.index, df[0], xdate=True);
~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in plot_date(x, y, fmt, tz, xdate, ydate, hold, data, **kwargs)
3261 try:
3262 ret = ax.plot_date(x, y, fmt=fmt, tz=tz, xdate=xdate, ydate=ydate,
-> 3263 data=data, **kwargs)
3264 finally:
3265 ax._hold = washold
~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1708 warnings.warn(msg % (label_namer, func.__name__),
1709 RuntimeWarning, stacklevel=2)
-> 1710 return func(ax, *args, **kwargs)
1711 pre_doc = inner.__doc__
1712 if pre_doc is None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot_date(self, x, y, fmt, tz, xdate, ydate, **kwargs)
1515 self.yaxis_date(tz)
1516
-> 1517 ret = self.plot(x, y, fmt, **kwargs)
1518
1519 self.autoscale_view()
~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
1708 warnings.warn(msg % (label_namer, func.__name__),
1709 RuntimeWarning, stacklevel=2)
-> 1710 return func(ax, *args, **kwargs)
1711 pre_doc = inner.__doc__
1712 if pre_doc is None:
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in plot(self, *args, **kwargs)
1436
1437 for line in self._get_lines(*args, **kwargs):
-> 1438 self.add_line(line)
1439 lines.append(line)
1440
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in add_line(self, line)
1757 line.set_clip_path(self.patch)
1758
-> 1759 self._update_line_limits(line)
1760 if not line.get_label():
1761 line.set_label('_line%d' % len(self.lines))
~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_base.py in _update_line_limits(self, line)
1779 Figures out the data limit of the given line, updating self.dataLim.
1780 """
-> 1781 path = line.get_path()
1782 if path.vertices.size == 0:
1783 return
~/anaconda3/lib/python3.6/site-packages/matplotlib/lines.py in get_path(self)
949 """
950 if self._invalidy or self._invalidx:
--> 951 self.recache()
952 return self._path
953
~/anaconda3/lib/python3.6/site-packages/matplotlib/lines.py in recache(self, always)
649 def recache(self, always=False):
650 if always or self._invalidx:
--> 651 xconv = self.convert_xunits(self._xorig)
652 x = _to_unmasked_float_array(xconv).ravel()
653 else:
~/anaconda3/lib/python3.6/site-packages/matplotlib/artist.py in convert_xunits(self, x)
189 if ax is None or ax.xaxis is None:
190 return x
--> 191 return ax.xaxis.convert_units(x)
192
193 def convert_yunits(self, y):
~/anaconda3/lib/python3.6/site-packages/matplotlib/axis.py in convert_units(self, x)
1489 return x
1490
-> 1491 ret = self.converter.convert(x, self.units, self)
1492 return ret
1493
~/anaconda3/lib/python3.6/site-packages/matplotlib/dates.py in convert(value, unit, axis)
1601 if units.ConversionInterface.is_numlike(value):
1602 return value
-> 1603 return date2num(value)
1604
1605 #staticmethod
~/anaconda3/lib/python3.6/site-packages/matplotlib/dates.py in date2num(d)
371 if not d.size:
372 return d
--> 373 return _to_ordinalf_np_vectorized(d)
374
375
~/anaconda3/lib/python3.6/site-packages/numpy/lib/function_base.py in __call__(self, *args, **kwargs)
2732 vargs.extend([kwargs[_n] for _n in names])
2733
-> 2734 return self._vectorize_call(func=func, args=vargs)
2735
2736 def _get_ufunc_and_otypes(self, func, args):
~/anaconda3/lib/python3.6/site-packages/numpy/lib/function_base.py in _vectorize_call(self, func, args)
2802 res = func()
2803 else:
-> 2804 ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
2805
2806 # Convert args to object arrays first
~/anaconda3/lib/python3.6/site-packages/numpy/lib/function_base.py in _get_ufunc_and_otypes(self, func, args)
2762
2763 inputs = [arg.flat[0] for arg in args]
-> 2764 outputs = func(*inputs)
2765
2766 # Performance note: profiling indicates that -- for simple
~/anaconda3/lib/python3.6/site-packages/matplotlib/dates.py in _to_ordinalf(dt)
220 tzi = UTC
221
--> 222 base = float(dt.toordinal())
223
224 # If it's sufficiently datetime-like, it will have a `date()` method
AttributeError: 'numpy.datetime64' object has no attribute 'toordinal'
Looks like something that may be fixed in the future...but for now, I converted my pandas datetime into a python datetime and used that
pydatetime = pd.Timestamp(item['datetime']).to_pydatetime()

Resources